Const
Statement
Gives a name to a value that does not change.
Syntax
Const declarator [ , declarator ]…
Parts
declarator
- Mandatory one or more declarations with a comma between each.
Declarator
name [ As type | In unit ] = expression
name
- Mandatory name for a value type.
type
- Optional elementary data type.
unit
- Optional unit of measure..
expression
- Mandatory constant expression.
Instructions
Const
is short for “constant”.
If a value in your program does not change, you can use a named constant as an alternative to a literal value. It is easier to think about a name than a value. You can define a constant one time and use it in many parts of your code. If subsequently you must change the value, there is only one change to make.
You can use Const
only at module level or procedure level.
It must be in one of these:
a class, a structure, a module, a procedure, or a block.
It cannot be in a namespace or trait.
See Declaration Contexts and Default Access Levels for more information.
Constants declared in a class or module (but not in a procedure) have private access. While those declared in a structure have public access.
The only permitted modifier for a constant is @Deprecated
to give a warning not to use it.
Constants operate the same as properties declared with all three modifiers @Backed
, @Shared
, and @ReadOnly
.
Rules
TODO
Examples
Const MaxLength As UInt = 32768
Const HTTP_GET = "GET", HTTP_POST = "POST"
Const ScalingFactor = 5.0 / 3.0