LOTUSSCRIPT LANGUAGE
Note You can specify OPTION DECLARE to force LotusScript to check for implicit declaration. It will generate a compile time error if any variables are not explicitly declared. It is recommended that applications be checked for implicit declaration before being released.
The following diagram summarizes the syntax for declaring a single scalar variable (in this example, a variable of type String):
The syntax elements in the declaration of a scalar variable are summarized in the following table:
When you declare a variable explicitly, LotusScript assigns it an initial default value:
Whether or not you append a data type suffix to the name of the variable when you declare it, you can always do so (or not) when referring to an explicitly declared scalar variable.
For example:
Public firstName$ Public lastName As String Dim age% Dim money As Currency firstName$ = "Roman" lastName$ = "Minsky" age% = 12 money@ = 150.75 Print firstName & " " & lastName & ", " & age &", $" & money ' Output: Roman Minsky, 12, $150.75 Print firstName$ & " " & lastName$ & ", " & age% &", $" & money ' Output: Roman Minsky, 12, $150.75
String variables
A variable of type String contains a sequence of characters in the Unicode character set. Unicode is a character-encoding system that uses two bytes to represent each character in the set. LotusScript converts input to Unicode format before compiling an application.
A String variable can be of variable or fixed length. The syntax for declaring a variable-length String variable is shown in the preceding diagram. The syntax for declaring a fixed-length String variable is shown below:
The charNum argument specifies that varName is a fixed-length String variable of charNum characters.
When you assign a string to a fixed-length String variable, LotusScript truncates the string or pads it to the declared length with trailing spaces if necessary.
Dim myName$ Dim myTown As String ' myName and myTown are variable-length string variables. Dim myState As String * 2 ' myState is a 2-character fixed-length String variable. Dim myZIP As String * 5 ' myZIP$ is a 5-character fixed-length String variable. ' If myZIP$ is assigned a value of more than 5 characters, ' that value will be truncated to its first 5 characters. myName$ = "Mark" myTown$ = "Centerville" myState$ = "MA" myZIP$ = "02100-9999" Print myName$ ' Output: Mark Print myTown$ & ", " & myState$ & " " & myZIP$ ' Output: Centerville, MA 02100
Declaring more than one variable at a time
The Dim statement and its variations allow you to declare more than one variable at a time at module level or within a procedure. At module level, the syntax is
{ Dim|Public| Private}varName1[ As dataType ], varName2 [ As dataType], ...
Within a procedure, the syntax is
{ Dim | Static } varName1 [ As dataType ], varName2 [ As dataType ], ...
It's important to explicitly declare all variables. For example:
Dim aString$, anInt%, aDouble As Double, aCurrency@ aString$ = "Hello" Print TypeName(aString$) & ": " & aString$ ' Output: STRING: Hello anInt% = 123 Print TypeName(anInt%) & ": " & anInt% ' Output: INTEGER: 123 aDouble# = 123.45 Print TypeName(aDouble) & ": " & aDouble# ' Output: DOUBLE: 123.45 aCurrency@ = 456.78 Print TypeName(aCurrency@) & ": " & aCurrency@ ' Output: CURRENCY: 456.78 Sub MySub Dim aString As String * 2, anotherString$, anInt% Static aDouble#, anotherDouble# aString$ = "Hi" Print TypeName(astring$) & ": " & aString$ anotherString$ = "World" Print TypeName(anotherstring$) & ": " & anotherString$ anInt% = 234 Print TypeName(anInt%) & ": " & anInt% aDouble# = aDouble# + 1 anotherDouble# = aDouble# * 2 Print TypeName(anotherDouble#) & ": " & anotherDouble# End Sub Call MySub ' Output: ' STRING: Hi ' STRING: World ' INTEGER: 234 ' DOUBLE: 2 Call MySub ' Output: ' STRING: Hi ' STRING: World ' INTEGER: 234 ' DOUBLE: 4
See Also