Remarks

You can use the single-line form (first syntax) for short, simple tests. However, the block form (second syntax) provides more structure and flexibility and is usually easier to read, maintain, and debug.

Note:

With the single-line form, you can execute multiple statements as the result of an If...Then decision, provided that you place the statements on one line and separate the statements by colons, as in the following statement:

If A > 10 Then A = A + 1 : B = B + A : C = C + B

When a block If (second syntax) is executed, condition is tested. If condition is True, the statements following Then are executed. If condition is False, each ElseIf (if any) is evaluated in turn. When a True condition is found, the statements following the associated Then are executed. If no ElseIf is True (or if no elseifstatements exist), the statements following Else are executed. After the statements following Then or Else are executed, execution continues with the statement that follows End If.

elsestatements and elseifstatements are optional. An If block can contain multiple elseifstatements, but no elseifstatement can be displayed after an elsestatement. Block If statements can be nested.

What follows the Then keyword is examined to determine whether a statement is a block If. Any statement, other than a comment, that is displayed after and on the same line as Then is treated as a single-line If statement.

A block If statement must be the first statement on a line. A block If statement must end with an End If statement.