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.

EXAMPLE 3<br />

The following program processes records.<br />

‘In BAS Module<br />

Public Type collegeData<br />

nom As String * 30<br />

state As String * 2<br />

yearFounded As Integer<br />

End Type<br />

’In Form code<br />

Private Sub cmdProcess_Click()<br />

Dim century As Integer, when As String<br />

‘Demonstrate use of records<br />

picResult.Cls<br />

Dim college As collegeData<br />

college.nom = txtCollege.Text<br />

college.state = txtState.Text<br />

college.yearFounded = Val(txtYear.Text)<br />

century = 1 + Int(college.yearFounded / 100)<br />

picResult.Print RTrim(college.nom); “ was founded in the” & Str(century);<br />

picResult.Print “th century in ”; college.state<br />

Dim university As collegeData<br />

university.nom = “M.I.T.”<br />

university.state = “MA”<br />

university.yearFounded = 1878<br />

If college.yearFounded < university.yearFounded Then<br />

when = “before ”<br />

Else<br />

when = “after ”<br />

End If<br />

picResult.Print RTrim(college.nom); “ was founded ”;<br />

picResult.Print when; RTrim(university.nom)<br />

End Sub<br />

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

Dim statements can be used in procedures to declare a local record variable. When<br />

records are passed to <strong>and</strong> from procedures, the parameter in the Private Sub or Function<br />

statement must have the form<br />

parameter As recordType<br />

User-Defined Data Types 249

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

Saved successfully!

Ooh no, something went wrong!