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

Microsoft Office Excel 2003 Programming Inside Out

                             Procedural programmers attempted to solve the problem by representing the things in their
                             environment using an abstract data type, which is a collection of characteristics and opera€
                             tions that reflect the values and actions associated with something you need to represent in a
                             program (such as a product). For example, a garden supply store could have both an indoor
                             sales area and a greenhouse, with products associated with each location. The abstract data
                             type product might have values reflecting the name of the product, the category to which the
                             product belongs, the product’s price, the product’s supplier, a description, and so on. It’s
                             important to note, however, that defining an abstract data type for a product doesn’t create a
                             place to hold the values and actions associated with that product. Instead, you would need to
                             create an instance of the product abstract data type to store the data and actions associated
                             with the new brand of potting soil you just started offering for sale in your garden supply
                             store. The instance would have a unique identifier within the system, such as product001, and
                             the program would know that the product name, category, price, description, and supplier
                             would all refer to that particular product.
                             While abstract data types are a handy way to define sets of variables in a program, the under-
                             lying structure of the programming languages that use abstract data types is still procedural
                             because there can be routines that exist outside of the abstract data types. In an object-oriented
                             programming language, every aspect of your computer code is based around the things in
                             your environment. Those “things,” not surprisingly, are represented as objects, and all actions
                             and data are encapsulated within those objects. In Excel, those objects could be workbooks,
             Chapter 3
                             worksheets, ranges of cells, or external files. In general, there are four aspects of objects you
                             can use to flesh out a program:
                               ●  Properties
                               ●  Methods
                               ●  Events
                               ●  Collections

                    Properties

                             In brief (actually, in total as well), properties are variables that describe some aspect of the
                             object in which they are included. A common property for objects in Excel is Name, which
                             holds the identifying value you or Excel assigned to the workbook, worksheet, cell range, or
                             other object to which you’re referring. If you change the worksheet’s name, whether by using
                             VBA code or by right-clicking the worksheet’s tab on the tab bar, clicking Rename, and edit€
                             ing the value, you change the value that is stored in the Name property. You can set new val€
                             ues for some worksheet properties (such as Name) directly, but to change other workbook
                             properties you need to either take action using the Excel interface (such as by protecting a cell
                             range) or a method (described in the next subsection).
                             In VBA, properties are referred to in a program using dot notation, where the object name is
                             written first, the property name is written second, and the two elements are separated by a
                             period. For example, to change the name of a worksheet, you would use the Worksheet.Name




                26
             Part 2:  Visual Basic for Applications
   47   48   49   50   51   52   53   54   55   56   57