Constants
[private | public] const identifier as type = expression
- Private – An optional keyword which ensures that a constant is only available from within the module it is declared. Constant declarations are private by default.
- Public – An optional keyword which ensures that a constant is available to other programs or modules.
- Identifier – A mandatory constant name, which follows the standard identifier naming conventions
- Type – A mandatory data type. Supported types include boolean, bit, byte, sbyte, short, ushort, integer, uinteger, single, string and char.
- Expression – A mandatory literal, constant declaration or a mixture of both.
A constant declaration can be used in a program or module in place of a literal value. Constant data cannot be changed at runtime (that is, you cannot assign a new value to a constant when your program is executing). However, constants have the advantage of making your code much more readable and manageable. You can declare constants one at a time, like this
Const maxSamples As Byte= 20 Const sizeOfArray As Byte = 20
You can also use an expression on the right hand side of a constant declaration. For example,
Const hello As String = "Hello" Const helloWorld As String = Hello + " World" Const valueA As Single = 12 * 0.4 Const valueB = valueA + 10
Constants, unlike program variables, do not use RAM to store their values. If a constant is used in a program expression, code memory is used instead. When declaring numeric constants, or when using numeric literals in your program, you can use different number representations.
| Representation | Prefix | Example | Value |
|---|---|---|---|
| Decimal | none | 100 | 100 decimal |
| Binary | &B | &B100 | 4 decimal |
| Octal | &O | &O12 | 10 decimal |
| Hexadecimal | &H | &H100 | 256 decimal |


