Visual Basic Concepts
An object is a combination of code and data that can be treated as a unit. An object can be a piece of an application, like a control or a form. An entire application can also be an object. The following table describes examples of the types of objects you can use in Visual Basic.
Example | Description |
Command button | Controls on a form, such as command buttons and frames, are objects. |
Form | Each form in a Visual Basic project is a separate object. |
Database | Databases are objects, and contain other objects, like fields and indexes. |
Chart | A chart in Microsoft Excel is an object. |
Each object in Visual Basic is defined by a class. To understand the relationship between an object and its class, think of cookie cutters and cookies. The cookie cutter is the class. It defines the characteristics of each cookie — for instance, size and shape. The class is used to create objects. The objects are the cookies.
Two examples of the relationship between classes and objects in Visual Basic may make this clearer.
The Properties window displays the class and Name property of objects in your Visual Basic application, as shown in Figure 5.8.
Figure 5.8 Object and class names shown in the Properties window
All objects are created as identical copies of their class. Once they exist as individual objects, their properties can be changed. For example, if you draw three command buttons on a form, each command button object is an instance of the CommandButton class. Each object shares a common set of characteristics and capabilities (properties, methods, and events), defined by the class. However, each has its own name, can be separately enabled and disabled, can be placed in a different location on the form, and so on.
For simplicity, most of the material outside of this chapter won't make many references to an object's class. Just remember that the term "list box control," for example, means "an instance of the ListBox class."