functions in the Letter template as well as generic utility sub-procedures
and functions in the Normal template. You can see this example in Chapter 13.
You might run into some situations like this when you create your Word
programs, too.
Another situation in which you use multiple projects is when you create pro-
grams in which multiple applications have to work together. I have a program
for Word that asks CorelDRAW to import a drawing and convert it into a form
that Word can use. Word receives the converted drawing and places it in the
current document. Word then asks Access to look up the drawing in a data-
base. Access performs this task and returns a description of the drawing to
Word, which then formats the description and places it under the drawing in
the current document. If I had to perform this whole loop every time that I
needed a drawing, it would take 20 minutes per drawing. My Word VBA pro-
gram can perform the task in less than a minute, and the results are perfect
every time.
Defining the program means figuring out how many building blocks you need
in order to accomplish a task. You can take the simple approach and use just
one project for many programs. However, don’t make life difficult. If you need
to use multiple projects, VBA makes it easy to use them.
Adding a module
Most of your beginning programs use a single module. However, good design
begins with module definitions. You could create a huge module called
utility
that contains every utility program you’ve ever written, but it would be a
mess. It’s like the overstressed dresser drawer that hides the tie tack or other
jewelry that you want to wear tonight: After you throw out all the contents of
the drawer into the room, you finally find the one item that you were looking
for. Instead of creating a single utility module, try creating a module for disk
utilities and another for data manipulation. Be unique! Try arranging your
modules to see what works best.
When your programming skills improve, you might want to interact with the
user in some way. You might want to ask the user questions, for example.
This task requires that you add a form to your program. Every form that you
want to create requires a separate form addition to the program. Make sure
that you create forms that ask for one kind of information — don’t confuse
the user by asking for all kinds of unrelated information on one form. (See
Chapter 7 for a description of forms and how to use them.)
Working with objects means using classes. To create a special object, add a
class module to your application. As when you’re adding forms, you should
add one class module for every new object that you want to create. Make
sure that any object that you create performs only one task. (Chapter 8
demonstrates methods for working with objects.)
69
Do'stlaringiz bilan baham: