Name
#If . . . Then . . . #Else Directive
Synopsis
#Ifexpression
Thenstatements
[#ElseIffurtherexpression
Then [elseifstatements
]] [#Else [elsestatements
]] #End If
expression
requiredAn expression made up of literals, operators, and conditional compiler constants that will evaluate to
True
orFalse
statements
requiredOne or more lines of code or compiler directives, which is executed if
expression
evaluates toTrue
furtherexpression
optionalAn expression made up of literals, operators, and conditional compiler constants that will evaluate to
True
orFalse
.furtherexpression
is only evaluated if the preceding expression evaluates toFalse
elseifstatements
optionalOne or more lines of code or compiler directives, which is executed if
furtherexpression
evaluates toTrue
elsestatements
optionalOne or more lines of code or compiler directives, which are executed if
expression
orfurtherexpression
evaluates toFalse
Description
Defines a block or blocks of code that are only included in the compiled application when a particular condition is 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:
Use the
#Const
directive to assign a value to a conditional compiler constant.Evaluate the conditional compiler constant using the
#If...Then...#End
If
statement block.
Only code blocks whose expressions evaluate to
True
are included in the executable. You can use
the #Else
statement to execute ...
Get VB.NET Language Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.