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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4. Methods can be either Function or Sub procedures. A method that returns a<br />

value must be a Function procedure; otherwise it can be a Sub procedure.<br />

5. A program with a class module has at least three components: a form, form<br />

code, <strong>and</strong> class module code. Although the View menu gives you access to the<br />

form (Alt/V/B) <strong>and</strong> the form code (Alt/V/C), only the Project Explorer gives<br />

access to all three. To view the code for a class module, double-click on the<br />

name of the class in the Project Explorer.<br />

6. A class module is saved in a file whose file name has the extension .cls. Therefore,<br />

classes have both a name (Csomething) <strong>and</strong> a file name (something.cls).<br />

7. To insert an existing (saved) class module into a program, click on Add Class<br />

Module in the Project menu, click on the Existing tab, <strong>and</strong> enter the filespec for<br />

the class module.<br />

8. To delete a class from a program, right click on the class name in the Project<br />

Explorer <strong>and</strong> click on Remove className.<br />

9. An object also can be declared with a statement of the form<br />

Private pupil As Object<br />

However, objects so declared require more time <strong>and</strong> effort for <strong>Visual</strong> <strong>Basic</strong> to<br />

access.<br />

10. The set of properties, methods, <strong>and</strong> events for a class is called the class interface.<br />

The classes CStudent <strong>and</strong> CPFStudent have the same interface, even<br />

though they carry out the task of computing a grade differently. The programmer<br />

need only be aware of the SemGrade method <strong>and</strong> needn’t be concerned<br />

about its implementation. The feature that two classes can have behaviors that<br />

are named the same <strong>and</strong> have essentially the same purpose but different implementations<br />

is called polymorphism.<br />

11. Sometimes you will have difficulty deciding whether an interface item should<br />

be a property or a method. As a rule of thumb, properties should access data <strong>and</strong><br />

methods should perform operations.<br />

12. The ByVal (which st<strong>and</strong>s for “by value”) keyword is automatically inserted<br />

before parameters in Property Let statements invoked from the Tools menu.<br />

However, this keyword is optional. The default way of passing an argument to<br />

a parameter is ByRef (which st<strong>and</strong>s for “by reference”). Usually, passing by<br />

value is more efficient than passing by reference.<br />

13. The default parameter name in a Property Let procedure is vNewValue.<br />

Although we usually substitute a meaningful name, we retain the convention of<br />

beginning the name with the prefix v.<br />

14. We could have preceded our member variables with the keyword Public <strong>and</strong><br />

allowed direct access to the variables. However, this is considered poor programming<br />

practice. By using Property Let procedures to update the data, we<br />

can enforce constraints <strong>and</strong> carry out validation.<br />

15. In a class module, a property is implemented by two procedures, one to set <strong>and</strong><br />

the other to retrieve the property value. These procedures that access properties<br />

are sometimes referred to as accessor methods.<br />

12.2 COLLECTIONS AND EVENTS<br />

Collections <strong>and</strong> Events 365<br />

“An object without an event is like a telephone without a ringer.”<br />

Anonymous<br />

A collection is an entity, similar to an array, that is especially well-suited to working with sets<br />

of objects. This section discusses collections of objects <strong>and</strong> user-defined events for classes.

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

Saved successfully!

Ooh no, something went wrong!