This statement declares a read-only variable for use in a procedure. Use the Dim statement for normal read-write variables.
[Public | Private] [Dim] Constvariable_name As type = init
Prerequisites
Parameters
variable_name
The name of the variable to be declared as a constant.
type
The type to be assigned to this variable. The type must be a primitive type or a String. The primitive type keywords are:
Boolean, Byte, Double, Integer, Short, Single
init
An expression that specifies the initial value for the new variable. It must have a constant value. It may only be composed of numeric or String constants, other Const variables, or built-in system functions.
Remarks
Only the Const statement can set the value of this variable. Everywhere else, an error occurs if an attempt is made to modify the value.
The Dim keyword is optional.
If both Public and Private are omitted, the default is Private.
Const variables declared within a class definition are implicitly Shared.
Unlike other declarations, only a single variable may be declared in one Const statement.
Const variables declared within a procedure definition are initialized in the order in which they occur and are known only within that procedure. Const variables outside procedures may arbitrarily make forward references to other Const variables.
Examples
Const c1 As Integer = 10
Const c2 As Integer = c1 + 1
Const ascii_a As Integer = ASC("a")
See Also