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 only 12 statements that you can use with this construct.
- method call
You cannot nest the one-line constructs of
This is because it can cause problems when some of the statements have
Else while other statements do not.
Changes in syntax with
There are three areas where you can change the syntax of the statement:
@Option If Thenand
@Option If End
@Option End Blockand
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