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]
-
condition Use: Required
Data Subtype: Boolean
An expression returning either
TrueorFalseor an object type.-
statements Use: Optional
Program code to be executed if
conditionisTrue.-
condition-n Use: Optional
Same as
condition.-
elseifstatements Use: Optional
Program code to be executed if the corresponding
condition-nisTrue.-
elsestatements Use: 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 theIfare 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access