Const If…Else
Statement
Lets you compile some code and ignore other code for different conditions.
Syntax
Const If condition [ Then ]
[ statements ]
[ Else If else_if_condition [ Then ]
[ else_if_statements ] ]
…
[ Else
[ else_statements ] ]
End [ If ]
Parts
Const
- Usually mandatory keyword.
You can use
@Const
as an alternative. condition
- Mandatory Boolean expression.
statements
- Optional one or more statements, compiled only if
condition
is true. Else If
- Optional keywords that you can use again and again.
else_if_condition
- Mandatory after
Else If
, a Boolean expression calculated only whencondition
(orelse_if_condition
before this one) is false. else_if_statements
- Optional one or more statements, compiled only when
elseif_condition
is true. else_statements
- Optional one or more statements, compiled only when
condition
and all ofelse_if_condition(s)
are false. End
- Completes the statement.
You can also use
End If
.
Instructions
The statement Const If…Else
lets you control which code compiles.
The syntax can make you think it operates the same as If…Else
.
But Const If…Else
operates at compile-time.
And If…Else
operates at run-time.
Usually you use conditional compilation to compile the same program for different platforms. You can also use it to keep debugging code out of the program file. All blocks of code after a false condition are ignored, almost the same as a comment. Thus they have no effect on the size or performance of the program file.
Note: There is no one-line construct for Const If…Else
as there is for If…Else
.
Const If
, Else If
, Else
, and End
must be on different lines.
And no other code can be on the same line.
The statements in a conditional-compilation block must be complete, correctly nested statements. For example, you cannot do conditional compilation on the modifiers for a property procedure. But you can declare the same property again with different modifiers.
Const If Debug Then
Property SomeProperty as String
Else
@ReadOnly Property SomeProperty As String
End If
Examples
Const If Debug Then
Const timeout = 60
Else
Const timeout = 600
End If