Name
Const Statement
Syntax
[accessmodifier
] Constconstantname
[Astype
] =constantvalue
-
accessmodifier
(optional; Keyword) One of the keywords
Public
,Private
,Protected
,Friend
, orProtected
Friend
. For more information, see Section 4.7 in Chapter 4.-
constantname
(required; String literal) The name of the constant.
-
type
(optional; Keyword) The data type; it can be
Byte
,Boolean
,Char
,Short
,Integer
,Long
,Single
,Double
,Decimal
,Date
, orString
, as well as any of the data types defined in the Base Class Library.-
constantvalue
(required; Numeric or String) A literal, constant, or any combination of literals and constants that includes arithmetic or logical operators, except
Is
.
Description
Associates a constant value with a name. This feature is provided to make code more readable. The name is referred to as a symbolic constant.
Rules at a Glance
The rules for
constantname
are the same for those of any variable: the name can be up to 255 characters in length and can contain any alphanumeric character, although it must start with an alphabetic character. In addition, the name can include almost any other character except a period or any of the data type definition characters ($, &, %, !).The
constantvalue
expression cannot include any of the built-in functions or objects, although it can be a combination of absolute values and operators. The expression can also include previously defined constants. For example:Private Const CONST_ONE = 1 Private Const CONST_TWO = 2 Private Const ...
Get VB.NET Language in a Nutshell, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.