LOTUSSCRIPT LANGUAGE
[Public | Private] Const constName = expression
Where:
' Define a String constant, MYNAME. Const MYNAME$ = "Andrea" ' Define a Single constant, MYPERCENT. Const MYPERCENT! = 0.125 ' Define a Currency constant, MYMONEY. Const MYMONEY@ = 123.45
Alternatively, if the constant is numeric, and expression is a numeric literal, you can specify the particular numeric data type by appending the appropriate data type suffix character to expression. For example:
' Define a Currency constant, MYCUR, with the value 123.45. Const MYCUR = 123.45@
If you donft append a suffix character to constName or expression, LotusScript determines the data type of the constant by the value of expression.
Const MYNAME = "Sara" ' MYNAME is a constant of type String. Const MYDOUBLE = 123.45 ' MYDOUBLE is a constant of type Double. Const MYINT = 123 ' MYINT is an constant of type Integer. Const MYLONG = 123456 ' MYLONG is a constant of type Long.
You can always include a data type suffix character when you refer to a constant in a LotusScript application, whether or not you used the suffix in the Const statement that defined the constant. You need not use the suffix, though it makes your code easier to read.
For example:
Const MYADDRESS$ = "722 Smith Place" Print MYADDRESS ' Output: 722 Smith Place
Const YOURADDRESS = "75 rue St. Viateur" Print YOURADDRESS$ ' Output: 75 rue St. Viateur ' Print MYADDRESS%, YOURADDRESS@ would cause an error.
Testing for the data type of a constant
You can determine the data type of a constant by calling either of two LotusScript functions: TypeName and DataType. TypeName returns a string indicating the data type of the expression being tested, and DataType returns a number representing the expressionfs data type.
Const MYMONEY@ = 123.45 Const MOREMONEY = MYMONEY * 2 Print TypeName(MOREMONEY) ' Output: CURRENCY Print DataType(MOREMONEY) ' Output: 6
The scope of a constant
Like variables, you can define a constant within a procedure or at module level (that is, outside the definition of a procedure, user-defined data type, or class). A constant that you define within a procedure is accessible only within that procedure though the procedure itself may be available to the whole module or application. If that constant has the same name as a constant or variable defined outside the procedure, LotusScript interprets references inside the procedure to that name as applying to the constant with the narrower scope, ignoring the existence of the constant or variable with the greater scope.
Const MYINT% = 10 ' This MYINT% is defined at module level. Sub MySub Const MYINT% = 100 ' This MYINT% is defined within a procedure. Print MYINT% End Sub Call MySub ' Output: 100 Print MYINT% ' Output: 10
By default, a constant that you define at module level is Private, that is, accessible only within that module. You can override this default in either of two ways to make the constant available to other modules in the application:
Public Const GLOBALINT% = 123
Use "A"
See Also