Const statement
Declares constants that are used in place of literal values.
[Public | Private] Const constname = expression
Parameters
Public
Options available. This keyword is used to declare constants that can be used in all procedures in all scripts at the script level. Not allowed for use in procedures.
Private
Options available. This keyword is used to declare constants in the script level that are available only in the script in which the declaration resides. Not allowed for use in procedures.
Constname
Required option. The name of the constant, according to the standard variable naming convention.
Expression
Required option. Text or other constants, or any combination of arithmetic operators and logical operators except is.
Description
Constants are public by default. Constants in the process are always proprietary and their visibility cannot be changed. In script, you can change the default value of script-level constant visibility by using the Private keyword.
To declare several constants in the same row, you can assign each constant to separate values with commas. When declaring a constant in this way, if the public or Private keyword is used, the keyword is valid for all constants in the row.
variables, user-defined functions, or VBScript intrinsic functions (such as Chr) cannot be used in a constant declaration. By definition, they cannot be constants. In addition, you cannot create constants from an expression that contains an operator, that is, only simple constants are allowed. A constant declared in a Sub or Function procedure is a local constant of the procedure. A constant declared outside a procedure is a global constant in the script where the declaration resides. Constants can be used wherever an expression is used. The following code provides an example of how to use the Const statement:
Const MyVar = 459
constants are public by default
. Const MyString = "HELP"
defines a private constant. Const MyStr = "Hello", MyNumber = 3.4567
'
define multiple constants on a single line.
Note that constants allow the script to support itself and are easy to modify. Unlike variables, constants cannot be inadvertently modified while the script is running.