You declare a constant using the Const statement. You can specify private or public scope and assign a value to the constant. If you don't specify scope, the constant has private scope by default. When naming constants, you must follow the same rules as when naming variables (for more information, see "Choosing Variable Names" earlier in this chapter).
A constant can represent data of any type, as shown in the following examples.
Const conPi = 3.14159265358979 Const conMaxPlanets = 9 Const conReleaseDate = #1/1/95# Const conCodeName As String = "Enigma"
You can place two or more constant declarations on a single line if you separate them with commas.
Const conPi = 3.14, conMaxPlanets = 9, _ conWorldPop = 6000000000#
The expression on the right side of the equal sign ( = ) is often a numeric value or string literal, but it can also be an expression that results in a number or string (although that expression cannot contain calls to functions). You can even define constants in terms of previously defined constants, as in the following example.
Const conPi2 = conPi * 2
After you've defined a constant, you can place it in your macro to make the macro more readable, as in the following example.
Static solarSystem(1 To conMaxPlanets) If numPeople > conWorldPop Then Exit Sub