Tuesday, September 4, 2007

Conditional Compilation in VB.NET

Like C and C++, you can perform Conditional Compilation in VB.NET:

#If COMMAND_LINE = True Then
Dim AxGTCreate1 As GTCREATELib.GTCreate = Nothing
Dim AxGTCreate1 As AxGTCREATELib.AxGTCreate = Nothing
#End If

The #if, #else, and #end if can be used.

In the example above, the variable COMMAND_LINE is used to determine which type to use. The COMMAND_LINE value is set either by using:

#Const COMMAND_LINE = True

in the code, or by setting it as a Custom Constant on the Compile table of the Project's property page. Press the Advanced Compile Options button to get to the form to set the Custom Constants.

No comments: