Declares constants for use in place of literal values.
Const constname = expression
Arguments
Const statement syntax has these named arguments:
Parameter |
Description |
|---|---|
Constname |
Required. Name of the constant; follows standard variable naming conventions. |
Expression |
Required. Literal or other constant, or a combination that includes all arithmetic or logical operators except Is. |
Remarks
You cannot use variables, user-defined functions, or intrinsic functions (such as Chr) in constant declarations, as by definition, they cannot be constants. You cannot create a constant from an expression that involves an operator. Only simple constants are allowed. 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
Const MyString = "HELP"
Note: Constants can make scripts self-documenting and easy to modify. Unlike variables, constants cannot be inadvertently changed while the script is running.