
This article is reprinted from the February 1991 edition of TechNotes/dBASE
IV.  Due to the limitations of this media, certain graphic elements such as
screen shots, illustrations and some tables have been omitted.  Where
possible, reference to such items has been deleted.  As a result,
continuity may be compromised.  

TechNotes is a monthly publication from the Ashton-Tate Software Support
Center.  For subscription information, call 800-545-9364.

Warming Up to Keyboard Macros
Joe Stolz

Most people's lives, and especially their daily computer activities, are a
specific set routine of procedures.  That's what causes our work-day lives
to become a bit stale.  The day in and day out routine leads us to feel
that we are forever stuck in a rut and unproductive.  It's ironic that,
when it comes to our computer work, if we could just do all the required
steps exactly the same way each time, we would get the same results each
time, life would be great.  We'd get more done in less time, look like
techno-whizzes to our superiors and feel better about the work we
produce.  

But, depending upon our  mood, the weather,  how much sleep we got, how
much training we were given, the amount of nurturing we  may have received
as children and a roster of other factors, it's sometimes difficult to
remember the exact steps that are required, for example, for a particular
report.  Our Support Technicians are commonly asked to aid someone in
recreating the circumstances required to produce a particular report.  If
only we all had photographic memories, then we could recall all the
requisite steps involved in the billing statement that was due last week.  

The most common way to handle repetitive tasks using dBASE has always been
to write a program.  Programs are swell, but not everyone feels competent
enough to plan out, write and debug a dBASE program.  So a user-friendly
microcosm of the programming concept was built into dBASE IV.  The new way
to handle these tasks is through a keyboard macro!

In the simplest cases, macros record every keystroke that you make during a
recording session.  You can edit the list of keystrokes to modify or delete
any mistakes made during the recording process.  Then you can simply play
the macro when you need to perform your task.  You must save your macros to
a library file stored on disk for use later, and you must load your library
prior to running your macros.

Using the Menu vs. Shift-F10

There are two main ways to record macros; from the Control Center and from
the dot prompt.  From the Control Center, you record macros by accessing
the Tools menu.  The first option in Tools: Macros is Begin recording. 
When you start to record a macro, you must first assign the macro a "hot
key".  This is basically the key that you press to begin playing out the
keystrokes of your macro.  

You will see a table of keystrokes available to be assigned to your macro
once you begin a recording session.  Your macros are easily assigned to a
function key: F1 through F9.  If you begin recording a macro and assign it
to F9, you will need to press Alt-F9 to play that macro.  If you assigned
the macro to the letter A, (you can assign all 26 letters, A through Z) you
play the macro by pressing Alt-F10 A.  Since there are menus available 
through Alt key sequences, it is necessary to prefix an alphabetic keywith
Alt-F10.  It is easy to verify the name of the macro by viewing the list of
available macros in the Tools menu 

 Depending on where you are in dBASE IV, pressing Alt followed by a letter
will either do nothing or pull down a menu.  

Names can be assigned to macros.  By default, the name of each macro is the
name of the key to which it is assigned.  In the previous example, the name
of the A macro is A.  You can give your macro a more descriptive name of up
to 10 characters maximum.

Macros can also be recorded at the dot prompt.  You do this by pressing
Shift-F10.  When you do this a small window pops up and asks whether you
want to begin recording a macro, or finish recording one if in the midst of
a macro recording session.  

This pop-up ability is available anywhere in dBASE IV including the Control
Center.  Actually, you can begin recording your macro in any design screen,
text editor, even in Help screens.  If you use the actual Tools menu
recording system, you must begin all your macros from the Control Center. 
Since you usually are going to open a file and perhaps run a report or some
labels, the Control Center is not such a bad place to begin running your
macro.  Further, only within the Tools menu can you see the table of all
your macros.  If you find it difficult to remember which macro you assigned
to which task, you should definitely start your macro recordings and
playbacks from the Tools menu where you have a full list of the available
macros in the current library.

If you do plan to have your macros play from the Control Center, be sure
that your keystrokes are specific ones.  Pressing Downarrow to move to your
favorite database file will not give the proper results if you create a new
database that takes the first alphabetic position in the data panel. 
Rather, have your macro type the first few unique letters of the file name
since that will make for a macro that will specifically pick out the
database that you want, regardless of its physical position among the other
files in the panel.

Macro Operations

A common error that first time macro users run into is in assuming that the
macro library is loaded automatically when you start up dBASE IV.  It's
quite easy to load a macro library and you must remember to do so every
time you enter dBASE IV or your macros will not be available for use.  You
could also have a startup routine load a predetermined library for you. 
The menu option that loads macro libraries is Tools: Macros: Load library. 
From the dot prompt or from a program a library can be loaded with the
command

RESTORE MACROS FROM <filename>

where filename is substituted by the name of an available macro file on
disk with the extension .KEY .

A second common and unfortunate error is in forgetting to save your newly
recorded macros into a library on the hard disk.  I've done it myself a few
times.  I've recorded a few macros, then inadvertently left dBASE IV to
move to another task.  Whoops!  So remember to save your macros to the disk
or they will disappear into the world of Tron when you quit!  The option
Tools: Macros: Save library is available from the Control Center for you to
save your macros.  If you are a dyed-in-the-wool dot prompt user, you still
may want to venture back to the Control Center for a more visual approach
to saving your macros before you quit.  It can help you a lot to verify the
existence of all your macros prior to saving the library.  You can still
use the SAVE MACROS TO command from the dot prompt if you are satisfied
with what you've recorded. 

Dej Vu 

An interesting feature of macro libraries is that they can be loaded on top
of one another.  This means that if one library is loaded and a second
library is loaded, those  macros that are assigned to the same keystroke
will be overwritten by those contained in the second library.  However,
keys that are not assigned in the second library will not be overwritten
(or blanked out) when the second library is loaded.  With a little stretch
of the imagination you can visualize a system of macros that are based on
an initial set of macros that are fine tuned by a second set of macros. 
The second and subsequent libraries are loaded and available depending on
the context of the application program in which they are available.  

It is common to accidentally add a few unnecessary keystrokes to your
macros during recording.  These can be easily edited out in the macro
editor, available only through the  Tools: Macros: Modify a macro option. 
Using the Menu System, page 14-6 has a complete list of the correct
spelling of each of the special keywords assigned to keystrokes such as
Backspace and PgUp by the dBASE IV macro editor.

Summary

Keyboard macros offer a full range of functions, from creation to
deletion.  You can edit macros, nest macros, insert user breaks (that allow
the user to insert data necessary for the rest of the macro) and so on. 
You can even use macros to record all the keystrokes in a particular
session to allow you to review the steps you took to get that report that
the boss wanted.  Get to know them.  They may come in handy some dreary day
when your concentration has ebbed to the point where you barely remember
your way to the coffee machine much less how to generate the end of month
figures.  s
