@Word in LotusScript

This function in LotusScript is equivalent to @Word function.

This Content Component encountered an error
This Content Component encountered an error

View member feedback to this tip.

This function in LotusScript is equivalent to @Word function:

Function Word(text As String, 
separateur As String, position As Integer) As 
String
posActual=0 
 If text <>"" And separateur <>"" 
And position <> 0
Then
  If position > 1 Then
   pos = position -1
  Else
   pos = position
  End If
  
  For i=1 To pos
   If position = 1 Then
    posActual = 0
   Else
    posActual =  Instr(posActual+1,text,separateur)
    If posActual = 0 Then
     Exit Function
    End If
   End If
   
   posNext =  Instr(posActual+1,text,separateur)
   
  Next
  
  If posNext <> 0 Then
   Word = Mid(text,posActual+1,posNext-(posActual+1)) 
  Else
   Word = Mid(text,posActual+1)
  End If
 End If
 
End Function

MEMBER FEEDBACK TO THIS TIP

Several points:

This is not really equivalent to @Word.

  • @Word handles multivalued inputs for the first argument, not just strings.

  • @Word allows a negative position value to count backwards from the right end of the string.

  • The variables have not all been "dim"ed. That's a flaw -- it's inefficient, and it won't compile if the programmer has specified Option Declare in their script. (Note: If I were hiring Domino developers, I would ask them for samples of their LotusScript code, and I wouldn't hire someone who doesn't always use Option Declare. It just makes sense.)

  • Years ago I posted LotusScript implementations of all the common list and string @functions, available now along with a bunch of other useful stuff at http://www-10.lotus.com/ldd/sandbox.nsf/0/816d64935ee8842485256c680051b592?OpenDocument. This includes a more complete implementation of @Word than this one (as well as a simpler version that does what this one does and also handles negative positions).

  • In ND6, the built-in StrToken function does the same thing as this function.

Andre Guirard, SearchDomino.com expert

******************************************

Andre's confirmation that LotusScript already contains an equivalent function to @Word highlights our community's tendency to keep reinventing wheels when IBM has already provided the wheels we're looking for. As you may recall, even when a function in Formula does not yet have a direct equivalent in LotusScript, one can always resort to use of the Evaluate() function, which evaluates Formula language within LotusScript and returns the result in an array:

Dim strSingleWord As String
Dim varEvaluateResult As Variant 
'Will store the evaluation result, 
bounds do not need to be specified
varEvaluateResult = Evaluate
 ( {@Word("Evaluate allows Formula 
to be called by
LotusScript"; " " ; 3)})
strSingleWord = varEvaluateResult(0) 
'In this case the array is single value 

—Tim T.

******************************************

Why do developers keep trying to reinvent the wheel? If you really want the power of "@Word", why not take it?

        Function AtWord$( YourString$, 
YourSeparator$, YourNumber )
                YourNumber = Evaluate
( {@Word( "} & YourString$ & {"; "} & 
YourSeparator$ & {"; } & YourNumber & { )} )
                AtWord$ = YourNumber( 0 )
        End Function 

Note that I reuse the "YourNumber" variant to contain the array that the Evaluate function returns. Then, I make the return value scalar.

Most programmers do not use the Evaluate function because they have had problems creating the proper syntax. The "Gotcha!" is the escape character and quotes. It's frustrating, I know, but once you have your "Es" and "Qs" down, you can build quick and efficient LotusScript functions for many, if not all, formulas in the Formula language.

—Randall S.

******************************************

ND6 users can use the StrToken LotusScript function as well.

—Joseph S.

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip library by member Evans Beeharry. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

This was first published in April 2004

Dig deeper on LotusScript

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close