Select...Case Statement

Executes one of several blocks of statements, because of a test expression.


Select [ Case ] test_expression [ Tol tolerance ]
    Case expression_list
        [ statements ]
    [ Case Else
        [ else_statements ] ]
End [ Select ]


Mandatory expression of an elementary data type.
Optional floating-point constant specifies the tolerance for rounding errors in comparisons. See Tol Clause for more information.

Mandatory after Case, one or more expressions for tests with test_expression with a comma between each. It can be one of the constructs that follow:

Range construct

expression_1 To expression_2

Comparison construct

Is comparison_op expression

Equality construct


The range construct lets you compare a range of values. The value of expression_1 must be less than or equal to expression_2.

The comparison construct lets you use all the comparison operators: <, <=, >, >=, =, or <>.

The equality construct is the same as if you used Is =.

Optional one or more statements after Case that execute if test_expression matches one of expression_list.
Optional one or more statements after Case Else that execute only if none of expression_list in all of Case match test_expression.
Completes the statement. You can also use End Select.


If test_expression matches one of Case expression_list, then control moves to the block of statements that follow it and continues until the next Case, Case Else, or End Select. Control then moves to the statement after End Select. If more than one match is possible, only the first of Case that matches gets executed.

The line Case Else introduces the else_statements, which get executed only when there are no matches between test_expression and all of the expression_list. Although not a requirement, it is considered a good practice to include one to handle any unexpected values of test_expression. If there are no matching Case blocks and no Case Else, then control moves to the statement after End Select.

Changes in syntax with @Option

There are three areas where you can change the syntax of the statement:

See @Option Directive for more information.


' FizzBuzz
For n = 1 To 100
    Select Case n Mod 15
    Case 0
        PrintLine "fizzbuzz"
    Case 3, 6, 9, 12
        PrintLine "fizz"
    Case 5, 10
        PrintLine "buzz"
    Case Else
        PrintLine n
    End Select
End For

See also