User Interaction |
10.1
Usually when a macro is played it executes its commands from
start to finish, and the macro ends. But sometimes you may want
to allow the user to do something in the "middle" of the macro,
during a pause in the execution of the macro. You can
do this by using the Pause() command. Or you
might want the macro to get input from the user while it is
running, which will then be used in the macro. This is
done with the GetString() and
GetNumber commands.
|
| GetString(x;"prompt") |
At the point where the macro executes this command, a dialog box will be displayed to the user. The dialog will contain text (represented by the "prompt" parameter) that is usually an explanation of the input required, and an edit field into which the user will type the input. When the dialog box is closed, the contents of the edit field are assigned to the variable whose name you specified as the first parameter (represented by x above).
As its name implies, the data accepted by the GetString() command is a string. Remember that you cannot perform arithmetic on strings. If you need to obtain a number from the user,, use the corresponding GetNumber() command. The data obtained from the user by GetNumber() is stored in the variable as a number. (See the topic strings v. numbers earlier in the tutorial.)
Examples:
To allow the user to specify a file to open:
| GetString(vFile;"Type name of file to open below") |
When the macro is played, the GetString() command would open a dialog box like this:
When the user clicks OK (or presses [ENTER]) to close the dialog, whatever the user typed in the edit field would be stored in the variable vFile. You could then use the FileOpen() command in the macro to open the file, passing vFile as the file name parameter:
| FileOpen(vFile) |
Allowing the user to specify what the macro should process makes the macro much more flexible. The same macro can open a different file each time it runs, depending on the value the user passes to the macro in the dialog box. Any time the same set of commands can be applied to different things, and the identification of those things can be obtained from the user, you should think of using GetString() or GetNumber().
© 1999 Seth H. Katz
All rights reserved
E-MAIL TO AUTHOR
![]() |
![]() |
![]() |