Caché Basic Reference
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   

Declares constants for use in place of literal values.
Const constname = expression
The Const statement syntax has these parts:
constname Name of the constant; follows standard variable-naming conventions.
expression Literal or any combination that includes all arithmetic or logical operators except Is.
To combine several constant declarations on the same line, separate each constant assignment with a comma.
You cannot use variables, user-defined functions, or intrinsic Caché Basic functions (such as Chr) in constant declarations. By definition, they cannot be constants. Constants declared in a Sub or Function procedure are local to that procedure. A constant declared outside a procedure is defined throughout the script in which it is declared. You can use constants anywhere you can use an expression.
The following code illustrates the use of the Const statement:
Const MyVar = 459

' Declare multiple constants on same line.
Const MyStr = "Hello", MyNumber  = 3.4567
Constants can make your scripts self-documenting and easy to modify. Unlike variables, constants cannot be inadvertently changed while your script is running.
See Also