Syntax#If expression Then statements [#ElseIf expression Then [statements]] [#Else [statements]] #End If
DescriptionThe #If...Then...#Else directive defines blocks of code that are only included in the compiled application when a particular condition is met or not met, allowing you to create more than one version of the application using the same source code. Conditionally including a block of code is a two-step process:
Only code blocks with expressions that evaluate to TRue are included in the executable. You can use the #Else statement to include code when none of the conditions are met. Use the #ElseIf portion any number of times to evaluate more conditions. Conditional compilation blocks can be used to include or exclude debugging code. Such code can be excluded from a release compilation of the project. They can also be used to conditionally include code in different editions of your application. For instance, your project may result in two outputs, one with limited features available at a lower price to your customers and one with more advanced features. Usage at a Glance
Example#Const UseAdvancedSet = True Private monitoredSet As Object Public Sub MonitorCorrectSet( ) #If UseAdvancedSet = True Then monitoredSet = New MyObject.AdvancedSet #Else monitoredSet = New MyObject.BasicSet #End If End Sub Only one of the assignment statements will appear in the compiled output; for the line that is not included, it will be as if the source code never included it at all. See Also#Const Directive |