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.

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

For instance, consider the situation of Example 1. If we are using social security number<br />

as a key, <strong>and</strong> the object pupil contains the data for Brittany Brown, then the statement<br />

section.Add pupil, “222-33-4444”<br />

would assign the string “222-33-4444” as a key for her data. Then her name property can<br />

be accessed with<br />

section.Item(“222-33-4444”).Name<br />

EXAMPLE 2<br />

Extend the program of Example 1 so that the grade for an individual student can be displayed by giving<br />

a social security number.<br />

SOLUTION:<br />

There are no changes in the two classes. In the Sub cmdAdd_Click procedure of the form code, change<br />

the line<br />

section.Add pupil<br />

to<br />

section.Add pupil, txtSSN.Text<br />

Place an additional comm<strong>and</strong> button (cmdDisplay) with the caption “Display Single Grade” on the form<br />

<strong>and</strong> add the following event procedure for this button:<br />

Private Sub cmdDisplay_Click()<br />

Dim ssn As String<br />

ssn = InputBox(“Enter the student’s social security number.”)<br />

picGrades.Cls<br />

picGrades.Print section.Item(ssn).Name; _<br />

Tab(28); section.Item(ssn).SocSecNum(); _<br />

Tab(48); section.Item(ssn).SemGrade<br />

End Sub<br />

When this comm<strong>and</strong> button is pressed, the input box in Figure 12-1 appears. To obtain the output in Figure<br />

12-2, run the program, enter the same data as in the execution of Example 1, press the “Display Single<br />

Grade” button, type 222-33-4444 into the input box, <strong>and</strong> press Enter.<br />

FIGURE 12-1 Input Box FIGURE 12-2 Output of Program

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

Saved successfully!

Ooh no, something went wrong!