The document discusses the problems with using multiple IF statements to handle different conditions for preparing for the weather. It can become confusing and inefficient to add new IF statements for each new condition. The document introduces using a SELECT CASE statement instead, which allows testing multiple conditions at once for a variable, like the weather. This is less confusing, easier to write and modify. An example SELECT CASE statement is provided to test the weather variable and take the appropriate action, like putting on a coat, sunglasses or snow joggers, in a cleaner way than multiple IF statements.
2. 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 dont know what to do!
Were going to have to
make another IF statement
3. 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! Were
going to have make another
IF statement
4. 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!
5. 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 isnt very efficient! Plus its confusing
6. 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
7. 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
8. 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