Page 325 - Microsoft Office Excel 2003 Programming Inside Out
P. 325

Chapter 14


                    Developing Class Modules




                             Introducing Class Modules . . . . . . . . . .  300   Building a Class . . . . . . . . . . . . . . . . . . . 305
                             Properties, Methods, and Events . . . . .  303   Practical Class Design . . . . . . . . . . . . . . 312



                             This chapter introduces the concept of classes. In this chapter, you’ll learn about classes,
                             objects and why they aren’t the same thing. You’ll also learn how to construct classes in
                             Microsoft Visual Basic for Applications (VBA), including defining their properties, methods,
                             and events.

                    What Is an Object?

                             An object is a logical representation of a thing. The thing can be a physical entity such as a
                             person, a flower, a machine, or a place. The thing can also be a logical entity such as a report,
                             an order, or a transaction. The thing can also represent something on the computer such as a
                             button, a cell, a worksheet, or a form.

                    What Is a Class?

                             A class is a template from which an object is created. This template includes both variables
                             and code that are wrapped together in a single entity. An object represents a single instance of
                             a class that can be manipulated by your program.
                             Confused? Think of a class as a data type such as Integer or String. Before you can use an Integer
                             or a String, you must declare a variable of that type. Just as you can have multiple variables
                             defined as Integers or Strings, you can have multiple variables defined as instances of a
                             single class.
                             Classes are implemented in Visual Basic for Applications through the class module. Each class
                             module holds exactly one class and includes all the properties, methods, and events associated
                             with the class’s interface, along with any other local variables, functions, and subroutines
                             needed to make the class work properly.


                    What Are Properties?
                             Properties are attributes of the thing an object represents. For example, a flower will have
                             attributes such as its name, its color, its size, and so on. A person’s attributes include name,
                             address, ID number, and birth date.





                                                                                                       299
                                                                                                Part 4:  Advanced VBA
   320   321   322   323   324   325   326   327   328   329   330