Top-Down Design

A good strategy for attacking a complex problem is to devise a clever way of breaking up the problem into sub-problems, and the sub-problems into smaller and smaller sub-problems until eventually they are so small and trivial that they can be solved individually.

Of course how that can be done is in general not necessarily trivial.

Exactly the same is true in writing complex computer programs. This strategy is often called top-down design.

VBA allows one to decompose a complex program into smaller sub-programs called procedures. There are two-types of procedures, one called Sub procedures and the other called Function procedures. This approach is called modular programming.

The former usually returns several results, whereas the later returns a single result.

In VBA, a calling (or main) Sub procedure invokes the other procedures as they are needed, and thus orchestrates each of the parts in a logical and modular fashion.

There are many good reasons for modular programming:

  1. Better Management of Large Projects -- Large and complex programs can be broken up into smaller more manageable pieces. Each piece can be worked on independently and at the same time by different groups of programmers.

  2. Code Reusability -- After a procedure has been coded and fully tested, it can be reused by any other programmers.

  3. Procedural Abstraction or Information Hiding -- In order to use a thoroughly tested function, the user only needs to know what the procedure does, and not how the procedure actually accomplishes the task. The procedure can be treated as a "black-box".

We will consider the Sub procedure and the Function procedure separately.