Multiway

Summary

Use a chain of If statements.

Situation

A variable has one of several distinct values, like different colors ("red", "green", or "blue"), or different ranges (1 to < 10, 10 < 30, ...). You want to do different things, depending on the value.

Needs

A variable with several distinct values or ranges.

Provides

Different program states, depending on the variable's value.

Action

Make a chain of If statements. An example for strings:

  • If tBreed = "australian cashmere" Then
  •     'Something.
  • ElseIf tBreed = "sarda" Then
  •     'Something.
  • ElseIf tBreed = "toggenburg" Then
  •     'Something.
  • Else
  •     'Something.
  • EndIf

An example for singles:

  • If sFollowers < 555 Then
  •     'Followers from 0 to < 555.
  •     tCondo = "Basic Billy"
  • ElseIf sFollowers < 5555 Then
  •     'Followers from 555 to < 5555.
  •     tCondo = "Comfy Cylde"
  • ElseIf sFollowers < 55555 Then
  •     'Followers from 5555 to < 55555.
  •     tCondo = "Luxury Lucy"
  • Else
  •     'Followers 5555 or more.
  •     tCondo = "One percent Juan"
  • End If