Name
#If...Then...#Else Directive
Syntax
#IfexpressionThen statements [#ElseIffurtherexpressionThen [elseifstatements]] [#Else [elsestatements]] #End If
-
expression Use: Required
An expression made up of literals, operators, and conditional compiler constants that will evaluate to
TrueorFalse-
statements Use: Required
One or more lines of code or compiler directives, which is executed if
expressionevaluates toTrue-
furtherexpression Use: Optional
An expression made up of literals, operators, and conditional compiler constants that will evaluate to
TrueorFalse.furtherexpressionis only evaluated if the preceding expression evaluates toFalse-
elseifstatements Use: Optional
One or more lines of code or compiler directives, which is executed if
furtherexpressionevaluates toTrue-
elsestatements Use: Optional
One or more lines of code or compiler directives, which are executed if
expressionorfurtherexpressionevaluates 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
#Constdirective to assign a value to a conditional compiler constant.Evaluate the conditional compiler constant using the
#If...Then...#EndIfstatement block.
Only code blocks whose expressions evaluate to
True are included in the executable. You can use
the #Else ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access