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 4, 5<br />

picOutcome.Print “You almost placed”<br />

picOutcome.Print “in the money.” Case Else<br />

picOutcome.Print “Out of the money.”<br />

End Select<br />

End Sub<br />

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

EXAMPLE 2<br />

In the following variation of Example 1, the value lists specify ranges of values. The first value list provides<br />

another way to specify the numbers 1, 2, <strong>and</strong> 3. The second value list covers all numbers from 4 on.<br />

Private Sub cmdDescribe_Click()<br />

Dim position As Integer<br />

‘Describe finishing positions in a horse race<br />

position = Val(txtPosition.Text)<br />

picOutcome.Cls<br />

Select Case position<br />

Case 1 To 3<br />

picOutcome.Print “In the money.”<br />

picOutcome.Print “Congratulations”<br />

Case Is > 3<br />

picOutcome.Print “Not in the money.”<br />

End Select<br />

End Sub<br />

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

The general form of the Select Case block is<br />

Select Case selector<br />

Case valueList1<br />

action1<br />

Case valueList2<br />

action2<br />

.<br />

.<br />

Case Else<br />

action of last resort<br />

End Select<br />

Select Case Blocks 113

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

Saved successfully!

Ooh no, something went wrong!