Objects Defined

Vertex42 The Excel Nexus

Professional Excel Templates

Get Instant Access

There is no need to get too abstract here with the definition of an object. It really is a pretty simple thing to understand. You can think of objects as separate computer programs with specific (and often common) functions that are available for repeated use in your programs. Objects are dynamic in that they can be easily manipulated in code with the various parameters used to define them.

In one common analogy, objects are equated as nouns in the English language. A programming object can be described with adjectives (properties), be capable of performing different actions with verbs (methods), and be built out of other objects. As an example, consider a bicycle. A bicycle can be described by its size, color, and type (among other things). For example, it might be a 26" blue ten-speed. The color, size, and type are all adjectives that describe the bicycle. Thus, they are all properties of the bicycle. A bicycle can also perform various actions; it can move straight or turn when ridden. Moving and turning are action verbs that tell you what tasks the bicycle can perform. Moving and turning are methods of the bicycle. Finally, the bicycle is built out of other objects such as a frame, wheels, handlebars, and pedals. These objects, in turn, have their own properties and methods. For example, a bicycle wheel is of a certain diameter, is built out of aluminum or titanium alloys, and it turns or rolls. The diameter and type of material are properties of the wheel object, and to turn or roll would be two of its methods. So you see, there is sort of a hierarchy to the objects in your bicycle and the bicycle object itself sits at the top of the hierarchy.

I could take it further. For example, a wheel is built from a tire, rim, and spoke objects. The tires are built from organic polymers, and so on, and so on. The description continues until eventually you will get to the objects at the very bottom of the hierarchy. These objects may have properties and methods, but they are not built out of any other objects. It may take you awhile to get to this level if you really think about your bicycle. Eventually you could break the bicycle down to its subatomic components. Of course, then you would have to stop because you would reach the limit of human knowledge. Fortunately, in any program, the object hierarchy does not extend that far and is well defined by the programmer. In this case, you get help from Excel and VBA in defining the objects, but it is still up to you to choose which objects you want or need to use in your program.

Now there is one more attribute of an object that has not yet been mentioned (at least not here; but it was discussed in Chapter 3). Consider what happens when a tire on your bicycle goes flat; or when the rider pedals the bicycle; or when the rider turns the handlebars on the bicycle. These are all events that occur when some action is carried out. Don't be confused with the method of the bicycle turning and the event of the rider turning the handlebars. They are not the sameā€”one depends on the other. In this particular case, the bicycle turns when the rider turns the handlebars. Events are actions triggered by an external stimulus of the object. You write code to use the turn_bicycle() method when the rider triggers the handlebar_turn() event. The code that is executed (invoking the turn_bicycle() method) is a coded response to the user's stimulus (handlebar_turn() event).

Object events are very powerful programming tools, as they allow for a much more interactive experience between the program and the user. Think about what a program would be like without events. Once you started the program running, you would not do anything else except maybe type in some information when prompted by the program. That is, the programmer would completely dictate the flow of the program. If you remember computers prior to GUI's then you may remember this kind of programming. You have already seen some of the events associated with a couple of Excel's objects in previous chapters. Now, you should have a little better understanding as to why events exist.

Now let's consider some of the objects in Excel. If you are a regular user of Excel or any spreadsheet program, then you are already familiar with many of its objects. For example, there are Workbook objects, Worksheet objects, Range objects, Chart objects, and many more. The rest of this chapter is devoted to showing you how to use a few of Excel's objects, and in particular, some of its top-level objects.

Was this article helpful?

0 0
Biorhythm Awareness

Biorhythm Awareness

Who else wants to take advantage of biorhythm awareness to avoid premature death, escape life threatening diseases, eliminate most of your life altering mistakes and banish catastrophic events from your life.

Get My Free Ebook

Post a comment