Name
If . . . Then . . . Else Statement
Syntax
Ifcondition
Then [statements
] [ElseIfcondition-n
Then [elseifstatements
] ... [Else [elsestatements
]] End If
Or, you can use the single-line syntax:
Ifcondition
Then [statements
] [Elseelsestatements
]
-
condition
Use: Required
Data Subtype: Boolean
An expression returning either
True
orFalse
or an object type.-
statements
Use: Optional
Program code to be executed if
condition
isTrue
.-
condition-n
Use: Optional
Same as
condition
.-
elseifstatements
Use: Optional
Program code to be executed if the corresponding
condition-n
isTrue
.-
elsestatements
Use: Optional
Program code to be executed if the corresponding
condition
orcondition-n
isFalse
.
Description
Executes a statement or block of statements based on the Boolean
(True
or False
) value of an
expression.
Rules at a Glance
If
condition
isTrue
, the statements following theIf
are executed.If
condition
isFalse
and noElse
orElseIf
statement is present, execution continues with the correspondingEnd
If
statement. Ifcondition
isFalse
andElseIf
statements are present, the condition of the nextElseIf
is tested. Ifcondition
isFalse
, and anElse
is present, the statements following theElse
are executed.In the block form, each
If
statement must have a correspondingEnd
If
statement.ElseIf
statements don’t have their ownEnd
If
. For example:If
condition
Thenstatements
ElseIfcondition
Thenstatements
End IfElseIf
andElse
are optional, and any number ofElseIf
andElse
statements can appear in ...
Get VBScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.