[Public|Private|Protected|Friend|Protected Friend] Const constname [As type] = expression
The Const statement syntax has these parts:
Part | Description |
---|---|
Public | Optional. Entities declared with the Public modifier have public access. There are no restrictions on the use of public entities. |
Private | Optional. Entities declared with the Private modifier have private access. A private entity is accessible only within its declaration context, including any nested entities. |
Protected | Optional. Entities declared with the Protected modifier have protected access. Protected access can only be specified on members of types (both regular type members and nested types), although there are different access rules for the two. A protected type member contained in a type is accessible to entities contained in a derived type, provided the access takes place through the derived type. A protected type nested in a type is accessible to entities contained in a derived type, provided the access takes place through the base type (since nested types are not inherited). Protected access is not a superset of friend access. |
Friend | Optional. Entities declared with the Friend modifier have friend access. An entity with friend access is accessible only within the program that contains the entity declaration. |
Protected Friend | Optional. Entities declared with the Protected Friend modifiers have the union of protected and friend accessibility. |
constname | Required. Name of the constant; follows standard variable naming conventions. |
type | Optional. Data type of the constant; may be Byte, Boolean, Char, Short, Integer, Long, Single, Double, Decimal, Date, String. Use a separate As type clause for each constant being declared. |
expression | Required. Literal, other constant, or any combination that includes all arithmetic or logical operators except Is. |
Constants are private by default. Within procedures, constants are always private; their visibility can't be changed.
You can't use variables, user-defined functions, or intrinsic Visual Basic functions (such as Chr) in expressions assigned to constants.
If you don't explicitly declare the constant type using As type, the type of the constant is the result type of the expression.
Constants declared in a Sub, Function, or Property procedure are local to that procedure. A constant declared outside a procedure is defined throughout the class, module or structure in which it is declared. You can use constants anywhere you can use an expression.
Const Directive | Function Statement | Sub Statement