Home > Language Reference > Program Flow Functions > SelectCase

SelectCase

The Select Case...EndCase satement executes one of several groups of statements, depending on the value of an expression. 

Usage

Select Case is similar to an If block but for more complex decisions where there are several possible answers. For example if you need to process different actions depending on which weekday it is, you will use a Select Case covering the 7 possible values for the current day.

Syntax

Select Case <test_expression>
        [Case <expression_1>
            <statements>]
        [Case <expression_2>
            <statements>]
        [...]
     [Case Else
        <statements>]
    EndSelect

Parameters

<test_expression>, numeric or string expression. If <test_expression> evaluates to one of the listed <expression_x>, the <statements> just after <expression_x> are executed.

Some possible <expression_x> are:
Case "a"
Case 1
Case a+b
Case "nom1","nom2","nom3"

If <test_expression> does not evaluate to any of the <expression_x>, the <statements> after Case Else are executed.

Example

 day=weekday()
    Select Case day
    Case 1
        aday$="Sunday"
    Case 2
        aday$="Monday"
    Case 3
        aday$="Tuesday"
    Case 4
        aday$="Wednesday "
    Case 5
        aday$="Thursday "
    Case 6
        aday$="Friday"
    Case 7
        aday$="Saturday"
    Case Else
        aday$="Impossible"
    EndSelect

    msgbox("Hello, today is: "+aday$)