Select Case Statement

Syntax:

Select Case expr
  [Case caseexpr[, ...]
  statements]...
  [Case Else
  statements]
End
Select

Group: Flow Control

Description:
Select the appropriate case by comparing the expr with each of the caseexprs. Select the Case Else part if no caseexpr matches. (If the Case Else is omitted then skip the entire Select...End Select block.)

caseexpr Description

expr Execute if equal.

Is < expr Execute if less than.

Is <= expr Execute if less than or equal to.

Is > expr Execute if greater than.

Is >= expr Execute if greater than or equal to.

Is <> expr Execute if not equal to.

expr1 To expr2 Execute if greater than or equal to expr1 and less than or equal to expr2.

See Also: If, Choose( ), IIf( ).

Example:

Sub Main
  S = InputBox("Enter hello, goodbye, dinner or sleep:")
  Select Case UCase(S)
  Case "HELLO"
  Debug.Print "come in"
  Case "GOODBYE"
  Debug.Print "see you later"
  Case "DINNER"
  Debug.Print "Please come in."
  Debug.Print "Dinner will be ready soon."
  Case "SLEEP"
  Debug.Print "Sorry."
  Debug.Print "We are full for the night"
  Case Else
  Debug.Print "What?"
  End Select
End
Sub