For those of you that have used the basic functions in Alpha Four, but have always been a little intimidated by scripts, the script recorder could be just what you need to take the next leap in programming.  While scripting isn't as straightforward as designing a form, the recorder can make the learning process much easier.

Simply put, the script recorder records the keystrokes you make when you are executing one or more functions, such as running a search and then printing a report.  Once these keystrokes have been recorded, you can retrieve them, and copy them to a script that is played from an object, such as a button or menu item.  From then on, all you have to do is "press" the button or other object, and the program will play your pre-recorded keystrokes.

To activate the script recorder, press ALT-F1.  In the bottom right corner of the screen (in the status bar), you'll see END:ALT-F3, which indicates that the recorder is turned on (and also tells you how to turn if off).  Now, press some keys (for example, LFSAV will select form A, and then go to View mode).  As you press each key, you should hear your computer beep at you.  This is how Alpha lets you know that you are recording.  Now, press ALT-F3 to turn the recorder off.  The message in the status bar will disappear.  

Now, press ALT-F3 to open the Scripts window, and press M to modify a script.  Press U, or scroll down until you get to a script called Untitled, and press ENTER.  This is where your keystrokes have been recorded.  If there were only a few keystrokes, you can see them all on this screen.  If you recorded more, simply arrow down to Keys/Commands, and press ENTER.  This will open a window in which you can view or edit the script.  For the example shown above, you should see LFSAV.

There are literally hundreds of things you can do from this point.  For example, you might want to rename this script, so you can use it again (remember that, every time you press ALT-F1 to start the script recorder, you will be overwriting whatever is in the script called Untitled).  You can also record another script, and then combine the two into once script.  To add the second script to the first one, record the second script, then open the Untitled script as described above.  With the cursor at the beginning of the script, press ALT-F5.  This will copy everything in the script.  Then, open the first script you saved, move the cursor to where you want the second script, and press ALT-F6.  This will paste the second script into the first.

Another nice thing about the script recorder is that you can correct mistakes.  For example, if you are recording, and select the wrong form, you can continue recording as you go back to select the correct form.  Then, you can delete the commands that were recorded in error.

Here's a neat trick that combines a script and user input.  Let's assume you are in a browse, and you want to change the value of the same field in multiple records.  Let's further assume that the new value will be similar, but not exactly the same, for each record; the value might be ABC follow by sequential numbers.  Here's how you could do it:

First, press C to go into change mode.  Then turn on the script recorder.  Then put in the first value (ABC21), press the DOWN key, and stop the recorder.  Now press ALT-F3 to get to the Scripts window, press M to modify, and find Untitled.  The script should look like this:

abc21{DN}

Now we'll modify the script.  Delete the 21, and put {PAUSE} in it's place.  This command pauses the script, waiting for the user to press ENTER.  Now, you'll want to play your script.  A quick way to play the Untitled script is to press ALT-F2.  This time, you will see ABC appear in the field.  Type 22 and press ENTER.  The script will continue playing, taking you to the record below.

Now, this script saved a few keystrokes.  But imagine if you were doing something more complicated -- the time saved could be substantial.  Also, this script was suitable for a one-time-only operation.  What about when you want to repeat the same operation over and over, and still have user input?

This is where scripting can really save time.  Let's assume that you want to run a report based on a customer's ID.  You will have to search for all records with the correct ID, then you have to run the report based on this search.1

First, you could design a saved search (search A), and insert a specific customer ID.  Then you could design your report (report C).  Then, you could turn on the script recorder, and record the keystrokes necessary to do this operation (SRAPRC).  However, this script will only be good for the specific ID that you used.  So, let's make it more versatile by using a script variable, instead of an ID.

What is a script variable?  This is like a container in memory, that will hold a value that is inserted at the time the script is played.  This means you have to have the user specify the value of the variable.  To do this, you'll use the PROMPT command.  This is a script command that pauses the script (similar to the PAUSE command you used earlier), waiting for the user to type a value.  This value becomes the script variable's value, which can then be used in the search.  Therefore, you have to modify the script to prompt the user.

First, you should change the name of the script you recorded, so you don't lose it.  To do this, press ALT-F3, then M, then find Untitled and press ENTER.  Change the name of the script by typing a new name to replace Untitled, and save it by pressing F10.  Now press ALT-F3 and M again, and go to the new script (assume it's called CUSTID).  Arrow down to Keys/Commands, and press ENTER.  Make sure the cursor is at the beginning of the script, and add the following:

{PROMPT "Enter Customer ID", %cust_id, 10}

Here is the complete script:

{PROMPT "Enter Customer ID", %cust_id, 10}
SRAPRC


Now, let's go back to the saved search, and change it to use this variable.  If you created your saved search using the Table mode, go to this point, and press F9 to go to Expression mode.  Now delete the value you used for the customer ID, and put in it's place {cust_id}.

When the script is played, the user will first be prompted for the customer's ID.  Then, the script will run the saved search (using the ID that the user entered), and then run the report.  You can run the script by pressing ALT-F3 and finding the script, or by attaching it to an application menu item in the Application Editor (see your manual for creating applications).  To do this, you would put:

{PLAY "CUSTID"}

into the Macro Keys in the Editor.

As you can imagine, there are many more things you can do with the script recorder.  These steps should get you started, so you can experiment on your own.

1 There are other ways to do this.  This example can also be applicable to these other methods.