Select Case... EndSelect

Program flow control function.

The Select Case...EndSelect structure defines a selection.

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 <tested_expression>
 [Case <expressions_1>
  <statements_1>]
 [Case <expressions_2>
  <statements_2>]
 [...]
 [Case Else
  <statements_3>]
EndSelect

Parameters

If <tested_expression> evaluates to one of the <expressions_>, the statements after the CASE are executed.

examples of <expressions_> are :
CASE "a"
CASE 1
CASE a+b
CASE "red" , "white" , "blue"

<expressions_> can any numeric or string expression.

After CASE ELSE, the <statements_3> are executed when the <tested_expression> does not evaluate to any of the <expressions_>.

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$)