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 Type: 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
statement 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 the block ...
Get VBScript in a Nutshell, 2nd Edition 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.