User-defined constants

You can define your own constants within a module or a procedure, as long as the constants are the scalar data types that LotusScript® recognizes. Use the following syntax to define a constant:

[Public | Private] Const constName = expression




Public, Private

Only an option when you declare a constant at module level, not within a procedure. Public means that the constant can be used outside the module in which it is defined. Private means the constant can only be used inside the module in which it is defined. Constants are Private by default.


The name of the constant. The name, which can include a data type suffix character, must be a legal LotusScript® identifier (see "Script and Statement Construction Rules"). A constant cannot have the same name as another constant, variable, or procedure of the same scope used in the same module.


An expression indicating the value of the constant. The expression can be a literal or another constant. You can use arithmetic and logical operators in the expression. The expression can contain a LotusScript® function (such as Abs or UCase$) if that function can be evaluated at compile time and its arguments (if any) are constant.

You can define a constant to be of a particular data type by appending a data type suffix to constName:


Data type













For example:

' 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 don't append a suffix character to constName or expression, LotusScript® determines the data type of the constant by the value of expression.

  • For a string, the data type is String.
  • For a Single or Double value, the data type is Double.
  • For an integer, the data type is Integer or Long, depending on the magnitude of the value.

For example:

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"
' Output: 722 Smith Place
Const YOURADDRESS = "75 rue St. Viateur"
' 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 expression's data type.

For example:

Const MYMONEY@ = 123.45
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.

For example:

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:

  • Include the keyword Public in the statement that defines the constant, for example:
    Public Const GLOBALINT% = 123
  • Include the Option Public statement at the beginning of a module that must be loaded when the application runs. This makes all identifiers in the module Public by default.

To access a Public constant defined in another module, you compile that module and then refer to the compiled module in a Use statement in the accessing module. (This is how you access any item defined as Public, whether a constant, variable, procedure, user-defined data type definition, or class definition.) For example, to access the Public constants in module A from module B, you compile module A and then include the following statement in module B:

Use "A"