lang • select

SELECT

SELECT [ CASE ] Expression
[ CASE [ Expression ] [ TO Expression #2 ] [ , ... ] ... ]
[ CASE [ Expression ] [ TO Expression #2 ] [ , ... ] ... ]
[ CASE LIKE Expression [ , ... ] ... ]
[ { CASE ELSE | DEFAULT } ... ]
END SELECT

Selects an expression to compare, and execute the code enclosed in the corresponding matching CASE statement.

If no CASE statement matches, the DEFAULT or CASE ELSE statement is executed.

A CASE statement is a list of single values or interval of two values separated by the TO keyword.

The first expression is optional: CASE TO Expression will match all values up to Expression.

Finally, you can match against a regular expression with the CASE LIKE syntax.

Examples

' You want to check the random function of a die.
' So you repeat the random function a thousand times
' and you count, how many times 1, 2, 3, 4, 5 or 6
' have been thrown.

Dim x As Integer
Dim w As Integer
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Dim e As Integer
Dim f As Integer

For x = 1 To 1000

  w = Int(Rnd(6) + 1)

  Select Case w
    Case 1
      a = a + 1
    Case 2
      b = b + 1
    Case 3
      c = c + 1
    Case 4
      d = d + 1
    Case 5
      e = e + 1
    Case 6
      f = f + 1
    Case Else
      Print "This is impossible!"
  End Select

Next

Print a, b, c, d, e, f

See also