Sex Pistols - God Save The Queen
If testexpression matches any Case expressionlist clause, the statements following that Case statement run up to the next CaseCase Elseor End Select statement. Control then passes to the statement following End Select. If case di video Sax matches an expressionlist clause in more than one Case clause, only the statements following the first case di video Sax run. The Case Else statement is used to introduce the elsestatements to run if no match is found case di video Sax the testexpression and an expressionlist case di video Sax in any of the other Case statements.
Although not required, it is a good idea to have a Case Else statement in your Select Case construction to handle unforeseen testexpression values. If no Case expressionlist clause matches testexpression and there is no Case Else statement, control passes to the statement case di video Sax End Select. You can use multiple expressions or ranges case di video Sax each Case clause.
For example, the following line is valid. The Is keyword used in the Case and Case Else statements is not the same as the Is Operatorwhich is used for object reference comparison.
You can specify ranges and multiple expressions for character strings. In the following example, Case matches any string that is exactly equal to "apples", has a value between "nuts" and "soup" in alphabetical order, or contains the exact same value as the current value case di video Sax testItem.
The setting of Option Compare can affect string comparisons. A Case statement with multiple clauses can exhibit behavior known as short-circuiting. Visual Basic evaluates the clauses from left to right, and if one produces a match with testexpressionthe remaining clauses are not evaluated. Short-circuiting can improve performance, but it can produce unexpected results if you are expecting every expression in expressionlist to be evaluated.
For more information on short-circuiting, see Boolean Expressions. If the code within a Case or Case Else statement block does not need to run any more of the statements in the block, it can exit the block by using the Exit Select statement. This transfers control immediately to the statement following End Select. Select Case constructions can be nested.
Each nested Select Case construction must have a matching End Select statement and must be completely contained within a single Case or Case Else statement block of the outer Select Case construction within which it is nested. The following example uses a Select Case construction to write a line corresponding to the value of the variable number.
The second Case statement contains the value that matches the current value of numberso the statement that writes "Between 6 and 8, inclusive" runs. Skip to main content. Exit focus mode. Theme Light. High contrast. Profile Bookmarks Collections Sign out. List of expression clauses representing match values for testexpression. Multiple expression clauses are separated by commas. Each clause can take one of the following forms: - expression1 To expression2 - [ Is ] comparisonoperator expression - expression Use the To keyword to specify the boundaries of a range of match values for testexpression.
The value of expression1 must be less than or equal to the value of expression2. If the Is keyword is not supplied, it is automatically inserted before comparisonoperator.
The expressions in expressionlist can be of any data type, provided they are implicitly convertible to the type of testexpression and the appropriate comparisonoperator is valid for the two types it is being used with. One or more statements following Case that run if testexpression matches any clause in expressionlist. One or more statements following Case Else that run if testexpression does not match any clause in the expressionlist of any of the Case statements.
End Select Terminates the definition of the Select Case construction. Remarks If testexpression matches any Case expressionlist clause, the statements following that Case statement run up to case di video Sax next CaseCase Elseor End Select statement.
Note A Case statement with multiple clauses can exhibit behavior known as short-circuiting. Is this page helpful? Yes No. Any additional feedback? Skip Submit. Send feedback about This product This page. You may also leave feedback directly on GitHub. This page. Submit feedback. There are no open issues. View on GitHub. Required in a Case statement.