Executes a sequence of statements because of a condition.
If condition [ Then ] [ statements ] [ Else If else_if_condition [ Then ] [ else_if_statements ] ] … [ Else [ else_statements ] ] End [ If ]
If condition Then statement [ Else else_statement ]
- Mandatory Boolean expression.
- Optional in the block construct
- Mandatory in the one-line construct
- Execute only when
- Optional in the block construct, one or more statements.
- Mandatory in the one-line construct, a one-line statement.
- Optional keywords that you can use again and again.
- Mandatory after
Else If, a Boolean expression calculated only when
else_if_conditionbefore this one) is false.
- Optional one or more statements, executed only when
- Optional one or more statements, executed only after
conditionand all of
- Completes the block construct.
You can also use
If…Else becomes too long, you can replace it with a Select…Case Statement.
You can use the one-line construct for short, easy tests. There are a small number of statements that can be used with this construct. They include:
- method call
Changes in syntax with
There are three areas where you can change the syntax of the statement:
@Option If With Thenand
@Option If Without Then
@Option If With End
@Option End With Blockand
@Option End Without Block
See @Option Directive for more information.
If x = 1
Then CallFirst End IfIf x = 1 Then CallFirst Else CallOther x End IfIf x = 1 Then CallFirst Else If x = 2 Then CallSecond Else If x = 3 Then CallThird Else CallOther x End IfIf x = 1 Then CallFirst If x = 1 Then CallFirst Else CallOther x