Name
Select Case Statement
Syntax
Select Casetestexpression[Caseexpressionlist-n[statements-n]] ... [Case Else [elsestatements]] End Select
-
testexpression Use: Required
Data Type: Any
Any numeric or string expression whose value determines which block of code is executed
-
expressionlist-n Use: Required
Data Type: 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
expressionlistandtestexpression-
elsestatements Use: Optional
Program statements to execute if a match between
testexpressionand anyexpressionlistcannot be found
expressionlist can use any (or a
combination of any) of the following:
|
expressionlist syntax |
Examples |
|---|---|
|
|
iVar - iAnotherVar iVar |
expression To expression |
5 To 10 8 To 11, 13 to 15 "A" To "D" |
Is comparisonoperator expression |
Is = 10 |
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
Caseclauses can be included in theSelectCasestatement.If a match between
testexpressionand any part ofexpressionlistis found, the program statements following the matchedexpressionlistwill be executed. When program execution encounters the nextCaseclause or theEndSelectclause, execution will continue with the statement immediately ...
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