Page 164 - Open Soource Technologies 304.indd
P. 164
Event Driven Programming
6: The color of the beacon light atop Boston’s John Hancock Building forecasts
the weather according to the following rhyme:
Steady blue, clear view.
Flashing blue, clouds due.
Steady red, rain ahead.
Flashing red, snow instead.
The following program requests a color (Blue or Red) and a mode (Steady
or Flashing) as input and displays the weather forecast. The program contains
a Select Case block with a string expression as selector.
Object Property Setting
frmWeather Text Weather Beacon
lblColor Text Color of the light (B or R):
mtxtColor Mask L
lblMode Text Mode (S or F ):
mtxtMode Mask L
btnInterpret Text Interpret Beacon
txtForecast ReadOnly True
Private Sub btnInterpret_Click(...) Handles btnInterpret.Click
‘Interpret a weather beacon
Dim color, mode As String
color = mtxtColor.Text
mode = mtxtMode.Text
Select Case mode.ToUpper & color.ToUpper
Case “SB”
txtForecast.Text = “CLEAR VIEW”
Case “FB”
txtForecast.Text = “CLOUDS DUE”
Case “SR”
158 LOVELY PROFESSIONAL UNIVERSITY