Const statement (LotusScript® Language)

Defines a constant.

Syntax

[ Public | Private ] Const constName = expr [ , constName = expr ]...

Elements

Public | Private

Optional. Public specifies that the constant is visible outside the module where the constant is defined, as long as that module is loaded. Private specifies that the constant is visible only within the module where the constant is defined.

A constant is Private by default.

If you declare a constant within a procedure, you cannot use Public or Private.

constName

The name of the constant.

expr

An expression. The value of the expression is the value of the constant.

The expression can contain any of the following.

  • Literal values (numbers and strings)
  • Other constants
  • Arithmetic and logical operators
  • Built-in functions, if their arguments are constant and if LotusScript® can evaluate them at compile time. The following functions are evaluated at compile time if their arguments are expressions including only literals and constants.

Functions that can be evaluated as LotusScript® constants

  • Abs
  • ACos
  • ASin
  • ATn
  • ATn2
  • Bin
  • Cos
  • DataType
  • Exp
  • Fix
  • Fraction
  • Hex
  • InStr
  • InStrB
  • Int
  • LCase
  • Left
  • LeftB
  • Len
  • LenB
  • Log
  • LTrim
  • Mid
  • MidB
  • Oct
  • Right
  • RightB
  • Round
  • RTrim
  • Sgn
  • Sin
  • Sqr
  • Str
  • Tan
  • TimeNumber
  • Trim
  • TypeName
  • UCase
  • UChr
  • Val

Usage

The Public keyword cannot be used in a product object script or %Include file in a product object script, except to declare class members. You must put such Public declarations in (Globals).

A constant is a named variable whose value cannot be changed. You can declare a constant in a module or a procedure, but you cannot declare a constant in a type or class definition.

You can specify the data type of a constant by appending a data type suffix character to constName. Alternatively, if the constant is numeric and expr is a numeric literal, you can specify the data type by appending a data type suffix character to expr.

If you do not append a data type suffix character to constName or expr, LotusScript® determines the data type of the constant by the value assigned to it.

  • For a floating-point value, the data type is Double.
  • For an integer value, the data type is Integer or Long, depending on the magnitude of the value.

These rules are illustrated in the examples following.

Whether you specify a suffix character in the Const statement or LotusScript® determines the data type based on the constant's value, you can use the constant in a script with or without a data type suffix character. If you use the constant with a suffix character, the suffix character must match the data type of the constant.

The data type of a constant is not affected by Deftype statements.

Example