Name
Select Case Statement
Syntax
Select Casetestexpression
[Caseexpressionlist
[statements-n
]] ... [Case Else [elsestatements
]] End Select
-
testexpression
Use: Required
Data Subtype: Any
Any numeric or string expression whose value determines which block of code is executed.
-
expressionlist
Use: Required
Data Subtype: Any
Comma-delimited list of expressions to compare values with
testexpression
.-
statements-n
Use: Optional
Program statements to execute if a match is found between any section of
expressionlist
andtestexpression
.-
elsestatements
Use: Optional
Program statements to execute if a match between
testexpression
and anyexpressionlist
can’t be found.
Description
Allows for conditional execution of a block of code, typically out of
three or more code blocks, based on some condition. Use the
Select
Case
statement as an
alternative to complex nested If...Then...Else
statements.
Rules at a Glance
Any number of
Case
clauses can be included in theSelect
Case
statement.If a match between
testexpression
and any part ofexpressionlist
is found, the program statements following the matchedexpressionlist
are executed. When program execution encounters the nextCase
clause or theEnd
Select
clause, execution continues with the statement immediately following theEnd
Select
clause.Both
expressionlist
andtestexpression
must be a valid expression that can consist of one or more of the following: a literal value, a variable, an arithmetic or comparison operator, or the value returned by an intrinsic ...
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.