Conditionally executes a sequence of statements as a result of a Boolean expression.
If condition [ Then ] [ statements ] [ Else If elseifCondition [ Then ] [ elseifStatements ] ] ... [ Else [ elseStatements ] ] End [ If ]
If condition Then statement [ Else elseStatement ]
- Required — A Boolean expression
- Optional in the long form
- Required in the short form
- Optional in the long form — One or more statements, executed only when condition is true..
- Required in the short form — One statement
- Required after Else If — A Boolean expression calculated only when the condition or elseifCondition before this is false.
- Optional — One or more statements, executed only when an elseifCondition is true.
- Optional — One or more statements, executed only after the condition and any and all elseifCondition expressions are false
- Completes the long form. Alternatively, you can use End If.
When an If...Then...Else statement becomes too long, you can replace it with a Select...Case Statement.
You can use the short form for short, easy tests. There are not many statements that can be used with this form. They include assignment, method call, Call, Call Event, End, Exit, GoTo Case, ReDim, Return, and Throw.
If Then End If If Then Else End If If Then Else If Then Else If Then Else End If If Then Else