O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Select Case Statement

Syntax

Select Case testexpression
   [Case expressionlist
      [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

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 expressionlist and testexpression.

elsestatements

Use: Optional

Program statements to execute if a match between testexpression and any expressionlist 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 the Select Case statement.

  • If a match between testexpression and any part of expressionlist is found, the program statements following the matched expressionlist are executed. When program execution encounters the next Case clause or the End Select clause, execution continues with the statement immediately following the End Select clause.

  • Both expressionlist and testexpression 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 or user-defined ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required