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 1<br />

<strong>and</strong> then an instance of the class is created inside a procedure with the statement<br />

Set pupil = New CStudent<br />

The object pupil will be local to the procedure. That is, it will cease to exist<br />

after the procedure has ended. The Property Let procedures are used to assign<br />

values to the member variables, <strong>and</strong> the Property Get procedures are used to<br />

retrieve values. The function SemGrade becomes a method for obtaining the<br />

student’s grade.<br />

Some examples are<br />

pupil.Name = “Adams, Al” ‘Assign a value to m_name<br />

picBox.Print pupil.Name ‘Display the student’s name<br />

picBox.Print pupil.SemGrade ‘Display the student’s semester grade<br />

The first statement calls the Property Let Name procedure, the second statement<br />

calls the Property Get Name procedure, <strong>and</strong> the third statement calls the<br />

method procedure SemGrade.<br />

The following program uses the class CStudent to calculate <strong>and</strong> display a student’s semester grade.<br />

‘Student Class (CStudent)<br />

Private m_name As String<br />

Private m_ssn As String<br />

Private m_midterm As Single<br />

Private m_final As Single<br />

Property Get Name() As String<br />

Name = m_name<br />

End Property<br />

Property Let Name(ByVal vName As String)<br />

m_name = vName<br />

End Property<br />

Property Get SocSecNum() As String<br />

SocSecNum = m_ssn<br />

End Property<br />

Property Let SocSecNum(ByVal vNum As String)<br />

m_ssn = vNum<br />

End Property<br />

Object Property Setting<br />

frm13_1_1 Caption Semester Grade<br />

lblName Caption Name<br />

txtName Text (blank)<br />

lblSSN Caption SSN<br />

txtSSN Text (blank)<br />

lblMidterm Caption Midterm<br />

txtMidterm Text (blank)<br />

lblFinal Caption Final<br />

txtFinal Text (blank)<br />

cmdEnter Caption &Enter Information<br />

cmdDisplay Caption &Display Grade<br />

cmdQuit Caption &Quit<br />

picGrade<br />

Classes <strong>and</strong> Objects 359

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

Saved successfully!

Ooh no, something went wrong!