Declaring Conditional Compilation Constants
You can set conditional compilation constants in one of three ways:
- In the Property Pages dialog box
- At the command line when using the command-line compiler
- In your code
Conditional compilation constants have a special scope and cannot be accessed from standard code. The scope of a conditional compilation constant is dependant on the way it is set. The following table lists the scope of constants declared using each of the three ways mentioned above.
|How Constant is Set||Scope of Constant|
|Property Pages dialog box||Public to all files in the project|
|Command line||Public to all files passed to the command-line compiler|
|#Const statement in code||Private to the file in which it is declared|
To set constants in the Property Pages dialog box
- Before creating your executable file, set constants in the Property Pages dialog box by following the steps provided in Setting Visual Basic Project Properties.
To set constants at the command line
- Use the /d switch to enter conditional compilation constants, as in the following example:
vbc MyProj.vb /d:conFrenchVersion=–1:conANSI=0
No space is required between the /d switch and the first constant.
Command-line declarations override declarations entered in the Property Pages dialog box, but do not erase them. Arguments set in Property Pages remain in effect for subsequent compilations.
When writing constants in the code itself, there are no strict rules as to their placement, since their scope is the entire module in which they are declared.
To set constants in your code
- Place the constants in the declaration block of the module in which they are used. This helps keep your code organized and easier to read.