176 Part II Programming Fundamentals
The first line copies the name of the selected list box item to the Text property of the
third label on the form (which you renamed lblCountry). The most important property
used in the statement is lstCountryBox.Text, which contains the exact text of the item
selected in the list box. The remaining statements are part of the Select Case decision
structure. The structure uses the lstCountryBox.SelectedIndex property as a test case
variable and compares it to several values. The SelectedIndex property always contains
the number of the item selected in the list box; the item at the top is 0 (zero), the second
item is 1, the next item is 2, and so on. By using SelectedIndex, the Select Case structure
can quickly identify the user’s choice and display the correct greeting on the form.
- Display the form again, and then double-click the Quit button (btnQuit).
The btnQuit_Click event procedure appears in the Code Editor.
- Type End in the event procedure.
- Click the Save All button on the Standard toolbar to save your changes. Specify the
C:\Vb10sbs\Chap06 folder as the location.
Now run the program, and see how the Select Case statement works.
Tip The complete Select Case project is located in the C:\Vb10sbs\Chap06\Select Case
folder.
- Click the Start Debugging button on the Standard toolbar to run the program.
- Click each of the country names in the Choose A Country list box.
The program displays a greeting for each of the countries listed. The following
screen shot shows the greeting for Italy: