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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

116 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

Private Sub cmdInterpret_Click()<br />

Dim firstName As String<br />

‘Quiz<br />

picAnswer.Cls<br />

firstName = txtName.Text<br />

Select Case firstName<br />

Case “Thomas”<br />

picAnswer.Print “Correct.”<br />

Case “Woodrow”<br />

picAnswer.Print “Sorry, his full name was”<br />

picAnswer.Print “Thomas Woodrow Wilson.”<br />

Case “President”<br />

picAnswer.Print “Are you for real?”<br />

Case Else<br />

picAnswer.Print “Nice try, but no cigar.”<br />

End Select<br />

End Sub<br />

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

EXAMPLE 5<br />

The following program has the selector Left(anyString, 1), a string expression. In the sample run, only the<br />

first action was carried out, even though the value of the selector was in both of the first two value lists.<br />

The computer stops looking as soon as it finds the value of the selector.<br />

Object Property Setting<br />

frm5_3_5 Caption Analyze First [~]Character of<br />

a String<br />

lblEnter Caption Enter any string<br />

txtString Text (blank)<br />

cmdAnalyze Caption Analyze<br />

picResult<br />

Private Sub cmdAnalyze_Click()<br />

Dim anyString As String<br />

‘Analyze the first character of a string<br />

picResult.Cls<br />

anyString = UCase(txtString.Text)<br />

Select Case Left(anyString, 1)<br />

Case “S”, “Z”<br />

picResult.Print “The string begins with a sibilant.”<br />

Case “A” To “Z”<br />

picResult.Print “The string begins with a nonsibilant.”<br />

Case “0” To “9”<br />

picResult.Print “The string begins with a digit.”<br />

Case Is < “0”<br />

picResult.Print “The string begins with a character of ANSI”<br />

picResult.Print “value less than 48 (e.g. +, &, #, or %).”

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

Saved successfully!

Ooh no, something went wrong!