Summary

Believe it or not, you now have a basic toolbox with which to begin furthering your skills as an Excel developer. In the process of learning how to use Excel's object model you'll be continually exposed

Identity Confusion: Am i a Property or a Method?

One of the reasons that differentiating between properties and methods is often difficult is that programmers don't always follow the conventions for naming properties and methods. The Count property is a good example. Generally speaking, methods are named using verbs or words that describe action, and properties are named using nouns. Based on the name, you'd expect to see Count classified as a method rather than as a property.

Based on the methods-as-verbs rule, the remedy for this situation would be to classify Count as a method or rename it using a more conventional property name such as Number. Granted, the term Number may not be as clear semantically as Count. In any event, it is not that big of a deal.

The main point is that developers often depart from existing conventions for one reason or another, and you should be aware of this as you develop your mental model. Remember, models are simulations that simplify the complexities of reality.

to the language features presented in this chapter (to better learn how to use your tools) and gradually exposed to additional features as they become relevant to the discussion (to expand your toolbox). Therefore, if you're feeling overwhelmed or confused, don't panic. Through the repetition and practice you'll be exposed to in the following chapters, it will become clear. In summary, focus on the following points:

♦ Organize your procedures in modules according to the functionality that each procedure helps provide.

♦ Although it is all right to use subroutines, try to find ways to integrate functions into your application. A function returns a value to the procedure that called it; a subroutine does not.

♦ Explicitly declare your variables using an appropriate data type where possible. Usually you'll use Strings, Integers, Longs, Booleans, and Doubles.

♦ Implement logic in your procedures using If. .Then.. .Else. • .End If or the Select Case statement.

♦ Implement looping using For.. .Next or Do.. .Loop.

Keep the concept of variable scope in mind. Variable scope refers to the breadth of a variable's visibility. A variable can be seen only by statements within a given procedure (a local or procedural level variable), by any statement within the same module (a module level variable), or by any statement in any open project (a global variable). Variable scope is determined by the location of the variables declaration and the use of the Public or Private keywords. It is best if you give a variable the narrowest scope possible.

Before we get into using the Excel object model, you need to acquire one more fundamental skill— debugging. You'll make mistakes no matter what your experience level. By developing sound debugging skills, you'll save yourself countless hours and a great deal of frustration. In the next chapter, you'll examine the various debugging features and explore some debugging techniques.

This page intentionally left blank

0 0

Post a comment