SELECT CASE
 THE FANCY IF
The Problem With IF . . .

IF it is cold out THEN you will put a coat on
ELSE leave the coat at home

          But what about if it rains!
          We don’t know what to do!

          We’re going to have to
          make another IF statement
The Problem With IF . . .
IF it is cold out THEN you will put a coat on
ELSE leave the coat at home
IF its raining THEN you will put a coat on
ELSE leave the coat at home
           But what if its sunny! We’re
           going to have make another
           IF statement
The Problem With IF . . .
IF it is cold out THEN you will put a coat on
ELSE leave the coat at home
IF its raining THEN you will put a coat on
ELSE leave the coat at home
IF its sunny THEN go and get you sunglasses
ELSE leave the sunglasses at home
          BUT WHAT IF ITS SNOWING!
The Problem With IF . . .
IF it is cold out THEN you will put a coat on
ELSE leave the coat at home
IF its raining THEN you will put a coat on
ELSE leave the coat at home
IF its sunny THEN go and get you sunglasses
ELSE leave the sunglasses at home
IF its snowing THEN go put on your snow joggers
ELSE leave the snow joggers at home
     This isn’t very efficient! Plus its confusing
Select Case To The Rescue!
• Select case is like IF but allows you to test
  many things at once in one construct

• This is
  – less confusing
  – Easier to type up
  – Easier to modify
Select Case To The Rescue!
 In Select case, a variable is tested using a criteria.


Case: Cold or                           Case: Sunny?
raining?                                Get your
Get your coat                           sunglasses
on!
                                        Case: Snow?
                                        Get your snow
                     Weather
                                        joggers on
Select Case in VB
Select Case WEATHER
    Case cold, raining
        put your coat on!
    Case sunny
        put your sunglasses on
    Case snow
        put your snow joggers on

End Select

Select case

  • 1.
  • 2.
    The Problem WithIF . . . IF it is cold out THEN you will put a coat on ELSE leave the coat at home But what about if it rains! We don’t know what to do! We’re going to have to make another IF statement
  • 3.
    The Problem WithIF . . . IF it is cold out THEN you will put a coat on ELSE leave the coat at home IF its raining THEN you will put a coat on ELSE leave the coat at home But what if its sunny! We’re going to have make another IF statement
  • 4.
    The Problem WithIF . . . IF it is cold out THEN you will put a coat on ELSE leave the coat at home IF its raining THEN you will put a coat on ELSE leave the coat at home IF its sunny THEN go and get you sunglasses ELSE leave the sunglasses at home BUT WHAT IF ITS SNOWING!
  • 5.
    The Problem WithIF . . . IF it is cold out THEN you will put a coat on ELSE leave the coat at home IF its raining THEN you will put a coat on ELSE leave the coat at home IF its sunny THEN go and get you sunglasses ELSE leave the sunglasses at home IF its snowing THEN go put on your snow joggers ELSE leave the snow joggers at home This isn’t very efficient! Plus its confusing
  • 6.
    Select Case ToThe Rescue! • Select case is like IF but allows you to test many things at once in one construct • This is – less confusing – Easier to type up – Easier to modify
  • 7.
    Select Case ToThe Rescue! In Select case, a variable is tested using a criteria. Case: Cold or Case: Sunny? raining? Get your Get your coat sunglasses on! Case: Snow? Get your snow Weather joggers on
  • 8.
    Select Case inVB Select Case WEATHER Case cold, raining put your coat on! Case sunny put your sunglasses on Case snow put your snow joggers on End Select