Thinking In Windows

Elements, Collections, Objects, Properties, Methods, and Procedures

Up until now the Microsoft Excel application team has given us collections of elements to work with.  At this point, we are going to go behind the scenes and see how they "program" these collections of elements.  The programming language that is used to "create" the Microsoft Excel application is called Visual Basic.  The Visual Basic programming language is an "object-oriented" language.  And, from the perspective of Visual Basic, each of the elements (except one, the "cell"*) in the collections that we have seen thus far are actually "objects."  For example, at the very highest level, Visual Basic sees our "accounting worksheet" ("spreadsheet") as an object to be used to calculate and display information.

As a real world analogy, consider the television.  It could be considered to be an object that is used to receive information and entertainment.

Each of the "objects" in Microsoft Excel have characteristics or properties that make the object useful by controlling the object's appearance or behavior.  Again, at the very highest level, a "worksheet" in Microsoft Excel has a "visible" property which you can use to "hide" / "unhide" a worksheet.  And, at a deeper level, the "Range" object has, for starters, the following properties:

    Column    -    returns the first column of the first cell in a range

    Height        -    returns the height of the range (in points [1/72 inch])

    WrapText    -    determines whether or not text wraps within the range

Again, in the real world, it could be said that the television has a "frequency" property which determines the channel you view.  Or, the television has a "volume" property which determines the level of sound you hear.

In addition to properties, the objects in Microsoft Excel also have methods - actions that the objects can do.  Back to the highest level, a worksheet has a calculate method which you can use to cause the entire worksheet to recalculate.  And, using the "Range" object again, it has, for starters, the following methods:

    Clear    -    clears the contents of the entire range

    Copy    -    copies the range to the clipboard

    Justify    -    rearranges the text in a range so that it fills the range evenly

    Table    -    creates a data table based on input values and formulas that you define on a worksheet

And, back to the real world, one could say that the television has a "MakeLouder" method that increases the volume property of the television object.

To sum up then.  At its simplest an object is data (or variables) surrounded by methods and / or properties.  Here's a picture worth a thousand words:

Here, again, we can go back to the basics, because there are only three things that can be "done" to (or by) an object by a Visual Basic programmer:

    1)  Change the object's condition by setting the value of one of the object's properties;

    2)  Examine the condition of an object by returning the value of one of the object's properties; and

    2)  Cause the object to perform a task that has been pre-defined as one of its methods.
 

* - Although you might expect a cell on a worksheet to be an object, cells are not objects in Microsoft Excel.  When a Visual Basic programmer wants to manipulate one or more cells, they must use the Range object.  To manipulate a single cell, they use a Range object that contains just that one cell.

If you have a question, then click here

Return to main menu