Skip to main content
Previous sectionNext section

Const

Declares constants for use in place of literal values.

Synopsis

Const constname = expression

Arguments

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.

Description

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.

Examples

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
Copy code to clipboard

Notes

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