Creating alert boxes in ST BASIC
by Ron Schaefer M.D.
One of the most valuable and user friendly parts of the ST's GEM operating system is the alert box. The alert box is a very familiar object to the ST user. It's that rectangle that pops up in the middle of your screen, usually before you are about to make a change to your file. It can ask you to make decisions (such as EXIT, CANCEL, etc.) simply by clicking your mouse button on another "button," actually, a smaller rectangle at the bottom of the alert box.
To create an alert box using ST BASIC is a relatively simple matter. For instance, you can pass some parameters to a subroutine which will then do all the dirty work (PEEKing and POKEing). The alert box or the GEMSYS(52) call, is part of the Application Environment Service, or AES for short. Before using any AES application you must first initialize a few variables, as demonstrated in the subroutine called INITAES. These variables are set equal to constants and need to be defined only once in a program, but this must be done before you attempt to make any GEMSYS calls. Not all of these variables are used by every AES application, but I have found it easiest to initiate them all at once, then forget about them.
Let's walk through the program. Line 10 is a comment, Line 20 calls the subroutine INITAES, and opens and clears the output window. Line 30 sets the type of icon that will appear on the left side of the Alert box. I did this by setting the string variable TYPE$ equal "1", the exclamation mark, "2", the question mark, "3", the stop sign, or blank " ", which prints nothing. Also, in line 30 the text appearing in the alert box is set equal to the string variable TEXT$. According to ST reference books, you can have up to five lines of text, each line up to 40 characters long. However, whenever my text got over 4 lines long or over 30 characters per line my system started crashing, so I kept within these constraints.
The string TEXT$ can be more than one line long, each line seperated by a "I", a character you get by pressing [SHIFT]\. This "I" serves the function of a carriage return, telling the alert box to start a new line. Text should not contain square brackets "[" or "]" since these have special meaning to the GEMSYS(52) routine.
In line 40 the text appearing in the buttons is set equal to the string BUTTON$. There can be from one to three buttons, with a maximum of 20 characters total. The different buttons are separated by a "I". Also in line 40 the default button is set. If it is set equal to 0 there is no default, otherwise one of the buttons is highlighted, and when a carriage return is pressed it has the same function as clicking on that particular button. Line 50 calls the subroutine DOALERT. Lines 60 through 80 print out a message, depending on which button you click.
The subroutine DOALERT starts on line 120. Line 130 sets a double precision variable "N#" equal to the memory location where the pararmeters must be POKEd in order to create an Alert box. Line 140 sets the default button as explained above. Line 150 generates the string ALERT$, which is a concatenation of the variables TYPE$, TEXT$, and BUTTON$, separated by square brackets. In line 160 the command VARPTR pokes the address of the string variable ALERT$ into the spot where the GEMSYS(52) routine will look for it. Line 170 calls the routine to generate an alert box. Finally, line 180 looks for which button you clicked and sets it equal to the variable CHOICE. A word of caution: When using GEMSYS commands it is very helpful if you frequently save your program. These commands are very finicky, and if they are not executed perfectly, they have a tendency to lock up or crash the system.