19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Case Else<br />

picResult.Print “The string begins with one of the following:”<br />

picResult.Print “ : ; < = > ? @ [ \ ] ^ _ ` ”<br />

End Select<br />

End Sub<br />

[Run, type Sunday into the text box, <strong>and</strong> press the comm<strong>and</strong> button.]<br />

EXAMPLE 6<br />

The color of the beacon light atop Boston’s John Hancock Building forecasts the weather according to the<br />

following rhyme. Write a program that requests a color (blue or red) <strong>and</strong> a mode (steady or flashing) as<br />

input <strong>and</strong> displays the weather forecast. The program should contain a Select Case block with a string<br />

variable as selector.<br />

Steady blue, clear view.<br />

Flashing blue, clouds due.<br />

Steady red, rain ahead.<br />

Flashing red, snow instead.<br />

Private Sub cmdInterpret_Click()<br />

Dim color As String, mode As String<br />

‘Interpret a weather beacon<br />

picForecast.Cls<br />

color = txtColor.Text<br />

mode = txtMode.Text<br />

Select Case UCase(mode) & UCase(color)<br />

Case “SBLUE”<br />

picForecast.Print “CLEAR VIEW”<br />

Case “FBLUE”<br />

picForecast.Print “CLOUDS DUE”<br />

Case “SRED”<br />

picForecast.Print “RAIN AHEAD”<br />

Case “FRED”<br />

picForecast.Print “SNOW AHEAD”<br />

End Select<br />

End Sub<br />

frmWeather Caption Weather Beacon<br />

lblColor Caption Color of the light<br />

txtColor Text (blank)<br />

lblMode Caption Mode (S or F)<br />

txtMode Text (blank)<br />

cmdInterpret Caption Interpret Beacon<br />

picForecast<br />

[Run, type red <strong>and</strong> S into the text boxes, <strong>and</strong> press the comm<strong>and</strong> button.]<br />

Select Case Blocks 117

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!