Name
Const Statement
Syntax
[Public|Private] Constconstantname=constantvalue
-
constantname Use: Required
The name of the constant.
-
constantvalue Use: Required
Data subtype: Numeric or String
A constant value, and optionally, arithmetic operators. Unlike variables, constants must be initialized.
Description
Declares a constant value: i.e., its value can’t be changed throughout the life of the program or routine. One of the ideas of declaring constants is to make code easier to both write and read; it allows you to replace a value with a recognizable word.
Rules at a Glance
The rules for
constantnameare the same as 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 datatype definition characters$ & % !.constantvaluecan be a string or numeric literal. It can be only a single value (a simple constant); that is, it cannot be an expression that includes a call to an intrinsic or user-defined function, property, or method, nor can it contain any arithmetic or string operators or variables. In addition, a constant can’t be defined in terms of another constant, as in the statement:Public Const CDATE = CSTART_DATE ' Invalid
The
Privatekeyword restricts the use of the constant to the module in which it’s defined, whereas thePublickeyword allows the constant to be used in all procedures ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access