Gives a name to a value that does not change.
Const declarator [ , declarator ]…
- Mandatory one or more declarations with a comma between each.
name [ As type | In unit ] = expression
- Mandatory name for a value type.
- Optional elementary data type.
- Optional unit of measure..
- Mandatory constant expression.
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
Const MaxLength As UInt = 32768 Const HTTP_GET = "GET", HTTP_POST = "POST" Const ScalingFactor = 5.0 / 3.0