Clear Macros, Restore Macros, Save Macros, Play
Macro, Set MacKey, Set("MacKey")
Maybe it's because there's
always been a whole programming language to play with, but
keyboard macros have never been a big thing in FoxPro. Other than
the defaults that used to be set up on the function keys (you
know, like F7 for DISPLAY MEMORY), we rarely record and use
macros in FoxPro. We never include macros in our applications.The
most important command in this group is CLEAR MACROS, which lets
you get rid of any defined macros—until VFP 5, it was usually the
defaults on the function keys we were clearing. We used RESTORE
MACROS occasionally, too, to get the defaults back. PLAY MACRO
executes a macro by name, while SAVE MACROS lets you store a
group of macros. Finally, SET MACKEY specifies which key starts
recording a macro.
This command should be part of the startup routine of any
VFP 3 or FoxPro 2.x application. That way, when the user drops
his pen or his cat on the keyboard, he won't end up with records
full of "SET" and "DISPLAY STRUCTURE." It doesn't hurt in VFP 5
and later, either, though there are no defaults in there.
Usage
|
RESTORE MACROS [ FROM MacroFile | FROM MEMO MemoField ]
SAVE MACROS TO MacroFile | TO MEMO MemoField
|
Macros can be stored in either of two places: a special
macro file (with an FKY for "function key" extension) or in a
memo field. In either case, they're stored in a special format
where two bytes are stored for each character. One byte stores
bit flags for the special modifier keys—Alt, Ctrl and Shift—while
the second character stores the keystroke. You can open an FKY
file or a memo field containing macros and see the commands, but
there's a lot more stuff in there, too. Check out the help topic
"Macro File Format (.FKY)" for the underlying format. Hacking one
of these files could lead to some cool applications, based on
replaying macro files, such as testing data-entry portions of
apps automatically.RESTORE MACROS by itself loads the macros from
a special file called DEFAULT.FKY. If you don't have that file,
it restores the (nonexistent since VFP 5) default function key
assignments.
Usage
|
PLAY MACRO MacroName [ TIME nDelay ]
|
As the name suggests, this command plays an existing
macro. The TIME clause is pretty cool—it lets you slow the thing
down in case there are places where you need to wait for FoxPro
to catch up. It's good for debugging macros, too. You can see
what's going on.Like KEYBOARD (often a good alternative), PLAY
MACRO doesn't actually make anything happen immediately. It
stores the name of the macro to be played back when the program
reaches a wait state (like BROWSE or READ EVENTS).This command's
behavior when you issue it more than once is yet another reason
we don't use macros in applications. If several PLAY MACROs have
been issued before a wait state, when the program finally reaches
a wait state, the macros are played in reverse order. The last
macro you played executes first. Bleh.
Usage
|
SET MACKEY TO [ KeyLabel ]
cKeyLabel = SET("MACKEY")
|
Through VFP 3, Shift+F10 brought up the Record Macro
dialog. Starting in VFP 5, Shift+F10 was taken over by the
context menus and there's no keystroke assigned for Record
Macro—you have to use the menu (from the Tools menu, choose
Macros, then Record). SET MACKEY lets you assign a key (or a
different key, in VFP 3 and FoxPro 2.x) for the task.
SET("MACKEY") tells you the current setting. If you SET MACKEY TO
without a key label, it restores the default setting—no shortcut
key in VFP 5 and later, Shift+F10 in earlier versions.
Example
|
RESTORE MACROS FROM MyMacros
PLAY MACRO ThisCoolMacro
CLEAR MACROS
|
Back to Table of Contents
Copyright © 2002-2018 by Tamar E. Granor,
Ted Roche, Doug Hennig, and Della Martin. Click for license
.