Name
If . . . Then . . . Else Statement
Syntax
IfconditionThen [statements] [ElseIfcondition-nThen [elseifstatements] ... [Else [elsestatements]] End If
Or, you can use the single-line syntax:
IfconditionThen [statements] [Elseelsestatements]
conditionUse: Required
Data Type: Boolean
An expression returning either
TrueorFalseor an object type.statementsUse: Optional
Program code to be executed if
conditionisTrue.condition-nUse: Optional
Same as
condition.elseifstatementsUse: Optional
Program code to be executed if the corresponding
condition-nisTrue.elsestatementsUse: Optional
Program code to be executed if the corresponding
conditionorcondition-nisFalse.
Description
Executes a statement or block of statements based on the
Boolean (True or False) value of an expression.
Rules at a Glance
If
conditionisTrue, the statements following theIfstatement are executed.If
conditionisFalseand noElseorElseIfstatement is present, execution continues with the correspondingEndIfstatement. IfconditionisFalseandElseIfstatements are present, the condition of the nextElseIfis tested. IfconditionisFalse, and anElseis present, the statements following theElseare executed.In the block form, each
Ifstatement must have a correspondingEndIfstatement.ElseIfstatements don’t have their ownEndIf. For example:If
conditionThenstatementsElseIfconditionThenstatementsEnd IfElseIfandElseare optional, and any number ofElseIfandElsestatements can appear in the block ...