LOTUSSCRIPT LANGUAGE
' Create an Integer variable without declaring it explicitly ' and initialize it to 1. counter% = 1
This has the same effect as the following explicit declaration and statement:
Dim counter% counter% = 1
As with explicitly declared variables, the identifier has to be a legal one and not already in use as the name of a constant, variable, or procedure in the same scope in the same module. If you append a data type suffix to the variable name when you declare it, that suffix determines data type of the variable. If you don't append a data type suffix, one of two things happens: if the name begins with a character covered by an existing Deftype statement, the variable is implicitly declared to be of the data type appropriate to that statement. Otherwise, the variable is implicitly declared to be of type Variant. The same rules apply to explicitly declared variables if the declaration doesnft contain an As dataType clause and the variable name doesnft end in a data type suffix character:
' Declare a variable of type Variant. Dim myVarV
Implicit declaration is a handy shortcut when you're writing a simple script, saving you the line of code that it would take to declare the variable explicitly. However, the line of code you save by collapsing the declaration of a variable and the assignment of a value into a single statement can be costly in an application of even moderate complexity for two reasons:
' Create the Integer variable anInt without explicitly ' declaring it and initialize it to 10. anInt% = 10 Print anInt ' Produce "Name previously declared" error ' because LotusScript reads anInt (without suffix character) ' as an implicitly declared Variant variable, not ' the Integer variable anInt% (with suffix character). ' Create the Variant variable myVariantV without explicitly ' declaring it and initialize it to 10. myVariantV = 10 Print myVariantV% ' Produce "Type suffix mismatch" error ' because myVariantV (without suffix character) was declared ' as type Variant, but the suffix character % is only ' appropriate for variables declared as type Integer.
If you want to disallow implicit declaration in a LotusScript application, include the Option Declare statement at module level in a module that you plan to have loaded when the application runs. This statement tells LotusScript to require explicit declarations for all your variables.
Note The Boolean and Byte data types do not have a data type suffix character and therefore cannot be declared implicitly.
Deftype statements
You use a LotusScript Deftype statement at module level to assign a default data type to variables whose names begin with a particular letter of the alphabet, donft end with a data type suffix character, and donft appear in an explicit declaration containing an As dataType clause. The statement must appear before any variables are declared in the module. The syntax is
Deftype range [, range]...
where type is a suffix such as Cur or Dbl, which is an abbreviation of the name of a data type, and range is one or more consecutive letters of the alphabet.
For example:
' Implicitly declared variables beginning with ' A, a, B, b, C, or c will be of type Integer. DefInt A-C ' Create the Integer variable anInt on the fly ' and initialize it to 10. anInt = 10 ' Create a variable of type Variant on the fly ' and initialize it to 2. It's a Variant because ' it doesn't have a data type suffix character and doesn't ' begin with any of the characters in the specified ' DefInt range. smallIntV = 2
See Also