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.

[Run, enter the data for a student (such as “Adams, Al”, “123-45-6789”, “82”, “87”), press the Enter<br />

Information button to send the data to the object, <strong>and</strong> press the Display Grade button to display the student’s<br />

name, social security number, <strong>and</strong> semester grade.]<br />

In summary, the following seven steps are used to create a class.<br />

1. Identify a thing in your program that is to become an object.<br />

2. Determine the properties <strong>and</strong> methods you would like the object to have.<br />

3. A class will serve as a template for the object. Add a class module from the Project<br />

menu.<br />

4. Set the name property of the class. (A common convention is to begin the name<br />

with the letter C.)<br />

5. For each of the properties in Step 2, declare a private member variable with a<br />

statement of the form<br />

Private m_variableName As dataType<br />

6. For each of the member variables in Step 5, create one or two public property<br />

procedures to retrieve <strong>and</strong> assign values of the variable. The general forms of<br />

the procedures are<br />

Public Property Get ProcedureName() As DataType<br />

ProcedureName = m_variableName<br />

(Possibly additional code.)<br />

End Property<br />

Public Property Let Procedurename(ByVal vNewValue As DataType)<br />

m_variableName = vNewValue<br />

(Possibly additional code.)<br />

End Property<br />

Note: Since the member variables were declared as Private, they cannot be accessed<br />

directly from outside an object. They can only be accessed through Property procedures<br />

which allow values to be checked <strong>and</strong> perhaps modified. Also, a Property procedure<br />

is able to take other steps necessitated by a change in a member variable.<br />

7. For each method in Step 2, create a Sub procedure or Function procedure to<br />

carry out the task.<br />

EXAMPLE 2<br />

Modify the program in Example 1 to calculate semester grades for students who have registered on a<br />

“Pass/Fail” basis. Use a class module to calculate the semester grade.<br />

Classes <strong>and</strong> Objects 361

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

Saved successfully!

Ooh no, something went wrong!