If... Then... Else statement
Execute a group of statements conditionally based on the expression value.
If condition Then statements [Else elsestatements ]
Alternatively, use the block Syntax:
If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements]] . . .
[Else
[elsestatements]]
End If
Parameters
Condition
One or more of the following two types of expressions:
Numeric or string expression. The operation result isTrueOrFalse. IfConditionIs Null, thenConditionConsideredFalse.
Expression in the format of TypeOf objectname Is objecttype. Objectname is a reference to any object, while objecttype is a valid object type. If objectname is an object type specified by objecttype, the expression is True; otherwise, it is False.
Statements
IfConditionIsTrueOne or more statements executed (separated by colons.
Condition-n
Same as condition.
Elseifstatements
IfCondition-nIsTrueOne or more statements that are executed.
Elsestatements
If noConditionOrCondition-nThe expression isTrueOne or more statements that are executed.
Description
For short and simple tests, you can use a single line (the first syntax ). However, the block form (the second syntax) provides more structured and adaptive than the single line form, making it easier to read, maintain, and debug.
Note:In a single-line syntax, You can execute multiple statementsIf... ThenBut all statements must be separated by colons on the same line, as shown in the following statement:
If A > 10 Then A = A + 1 : B = B + A : C = C + B
When the program runsIfBlock (second syntax), the testCondition. IfConditionYesTrue, Then executeThen. For exampleConditionYesFalse, Then eachElseIfSome conditional statements (if any) are calculated and tested in sequence. WhenTrueIs relatedThenThe subsequent statement is executed. If noneElseIfStatement isTrue(Or noElseIfClause ),Else. RunThenOrElseThe subsequent statement will be executed later.End If.
ElseAndElseIfClauses are optional. InIfBlock can be placed in any numberElseIfClause, but both must be inElseClause.IfBlock statements can be nested, that is, they are included in anotherIfBLOCK statement.
To determine whether a statement isIfBlock, can be checkedThenWhat is after the keyword. IfThenThe statement is in the form of a single row.IfStatement.
IfThe block statement must be the first statement of a row and must startEnd IfThe statement ends.