Executes one of several groups of statements, depending on the value of an expression.
Select Case testexpression
[statements-n]] . . .
[Case Else elsestatements]
If testexpression matches (is equal to) any Case
expressionlist expression, the statements following that Case
clause are executed up to the next Case
clause, or for the last clause, up to End Select
. Control then passes to the statement following End Select
. If testexpression matches an expressionlist expression in more than one Case
clause, only the statements following the first match are executed.
The Case Else
clause is used to indicate the elsestatements to be executed if no match is found between the testexpression and an expressionlist in any of the other Case
selections. Although not required, it is a good idea to have a Case Else
statement in your Select Case
block to handle unforeseen testexpression values. If no Case
expressionlist matches testexpression and there is no Case Else
statement, execution continues at the statement following End Select
The following example illustrates the use of the Select Case
Dim Color, MyVar
Sub ChangeBackground (Color)
MyVar = lcase (Color)
Select Case MyVar
Case "red" document.bgColor = "red"
Case "green" document.bgColor = "green"
Case "blue","azure" document.bgColor = "blue"
Case Else Print "pick another color"
© 1997-2019 InterSystems Corporation, Cambridge, MA