This documentation is archived and is not being maintained.

3.1 Conditional Compilation

Visual Studio .NET 2003

Conditional compilation controls whether sequences of logical lines are translated into actual code. At the beginning of conditional compilation, all logical lines are enabled; however, enclosing lines in conditional compilation statements may selectively disable those lines within the file, causing them to be ignored during the rest of the compilation process. Because the conditional compilation process is done after lexical analysis, even disabled lines must be lexically valid.

For example, the program

#Const A = True
#Const B = False
Class C
#If A Then
    Sub F()
    End Sub
#Else
    Sub G()
    End Sub
#End If
#If B Then
    Sub H()
    End Sub
#Else
    Sub I()
    End Sub
#End If
End Class

produces the exact same sequence of tokens as the program

Class C
    Sub F()
    End Sub

    Sub I()
    End Sub
End Class
Start ::= [ ConditionalElement+ ]
ConditionalElement ::= 
   ConditionalConstantDeclaration | 
   ConditionalIfGroup | 
   LogicalLine

See Also

3.1.1 Conditional Constant Directives | 3.2 External Source Directives | 3.3 Region Directives | Compiler Directive Summary (Visual Basic Language Reference) | Conditional Compilation Overview (Visual Basic Language Concepts)

Show: