Const

Declares constants for use in place of literal values.

Syntax

[Public | Private] Const constname = expression

The Const statement syntax has these parts:

Part Description
Public Optional. Keyword used at module level to declare constants that are available to all procedures in all modules. Not allowed in procedures.
Private Optional. Keyword used at module level to declare constants that are available only within the module where the declaration is made. Not allowed in procedures.
constname Required. Name of the constant; follows standard variable naming conventions.
expression Required. Literal or other constant, or any combination that includes all arithmetic or logical operators except Is.

Remarks

Constants are public by default. Within procedures, constants are always private; their visibility can't be changed. Within a module, the default visibility of a module -level constant can be changed using the Private keyword.

To combine several constant declarations on the same line, separate each constant assignment with a comma. When constant declarations are combined in this way, the Public or Private keyword, if used, applies to all of them.

You can't use variables, user-defined functions, or intrinsic Visual Basic for Windows CE run-time functions (such as Chr) in constant declarations. By definition, they can't be constants. You also can't create a constant from any expression that involves an operator, that is, 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 module in which it is declared. You can use constants anywhere you can use an expression.

Note Constants can make your code self-documenting and easy to modify. Unlike variables, constants can't be inadvertently changed while your program is running.