""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
   MAKING APPLICATION MENUS & MESSAGES MORE R:BASE-LIKE
   """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
   PRODUCT   :  R:BASE                  VERSION      :  3.1
   CATEGORY  :  PROGRAMMING             SUBCATEGORY  :  TOOLS
   """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
   Here are three routines and an undocumented feature that you can use
   to make your application menus and messages look like they do in
   R:BASE:
 
     o  Simulate the output device menu.
     o  Return to a previous menu option.
     o  Make red-bar error messages.
 
 
   R:BASE Output Device Menu
   """""""""""""""""""""""""
   OUTPUT.CMD presents the user with a check box to select the desired
   output devices. This routine simulates the menu that R:BASE uses to
   prompt for the output device when you print a report from the R:BASE
   main menu. One advantage to this routine is that you are allowed to
   select all three output devices at once. The R:BASE main menu only
   allows you to select up to two devices at once.
 
     *( OUTPUT.CMD--Prompt for specific output)
     *( devices; return VOUTPUT--TEXT variable)
     *( that holds the OUTPUT command.)
     SET VAR vresp TEXT
     CHOOSE vprint FROM output.mnu +
       AT 09,28 black ON cyan CLEAR
     SET VAR vprint = (.vprint + ',')
     SET VAR v1option = (SSUB(.vprint,1)), +
       v2option = (SSUB(.vprint,2)),+
       v3option = (SSUB(.vprint,3))
     SWITCH (.v1option)
       CASE 'Create text file...'
         DIALOG 'Enter file name:' vfile vresp 1
         SET VAR v1option = .vfile
         BREAK
       CASE 'Show on screen'
         SET VAR v1option = 'SCREEN'
         BREAK
       CASE 'Printer'
         SET VAR v1option = 'PRINTER'
         BREAK
       DEFAULT
         SET VAR v1option = NULL
     ENDSW
     SWITCH (.v2option)
       CASE 'Create text file...'
         DIALOG 'Enter file name:' vfile vresp 1
         SET VAR v2option = .vfile
         BREAK
       CASE 'Show on screen'
         SET VAR v2option = 'SCREEN'
         BREAK
       CASE 'Printer'
         SET VAR v2option = 'PRINTER'
         BREAK
       DEFAULT
         SET VAR v2option = 'NONE'
     ENDSW
     SWITCH (.v3option)
       CASE 'Create text file...'
         DIALOG 'Enter filename:' vfile vresp 1
         SET VAR v3option = .vfile
         BREAK
       CASE 'Show on screen'
         SET VAR v3option = 'SCREEN'
         BREAK
       CASE 'Printer'
         SET VAR v3option = 'PRINTER'
         BREAK
       DEFAULT
         SET VAR v3option = 'NONE'
     ENDSW
     IF v3option = 'NONE' THEN
       IF v2option = 'NONE' THEN
         IF v1option IS NULL THEN
           SET VAR voutput = 'ABORT'
         ELSE
           SET VAR voutput = .v1option
         ENDIF
       ELSE
         SET VAR voutput = (.v1option +
           & 'WITH' & .v2option)
       ENDIF
     ENDIF
     IF v3option <> 'NONE' THEN
       IF vresp = '[Esc]' THEN
         SET VAR voutput = +
           ('PRINTER WITH SCREEN')
       ELSE
         SET VAR voutput=(.vfile & 'WITH BOTH')
       ENDIF
     ENDIF
     CLEAR VAR vprint, v1option, +
       v2option, v3option, vfile, vresp
     RETURN
 
   Here's OUTPUT.MNU, the menu file used by OUTPUT.CMD:
 
     OUTPUT.MNU
     CHKBOX |Select Print Routing|
     |Printer| |Printer output|
     |Create text file...| |File output|
     |Show on screen| |Screen output|
 
   The CHOOSE command in OUTPUT.CMD collects the output devices from the
   user. Then the series of SWITCH...ENDSW blocks construct the correct
   syntax for the OUTPUT parameters depending on whether the user chose
   one, two or all three devices. At the end of the program, the TEXT
   variable VOUTPUT contains the correct OUTPUT parameters.
 
   Use the following two commands to run OUTPUT.CMD and send output to
   the devices the user chooses:
 
     RUN output.cmd
     OUTPUT &voutput
 
 
   Return to Previous Menu Option
   """"""""""""""""""""""""""""""
   When you choose an option using the R:BASE menus, R:BASE always
   remembers the option the cursor was sitting on when you made the
   choice. When R:BASE returns to the previous menu, that remembered
   option is highlighted.
 
   But when you create your own application with pull-down menus, this
   return option doesn't work the same way. When a user selects an option
   and later returns to the application's main menu, R:BASE highlights
   the upper left option instead of the last-used option.
 
   Fortunately, you can change this by adding code to your application.
   Use the command file MAKEPLAY.CMD listed below. Basically, you run
   MAKEPLAY.CMD, passing it the pull-down number and the menu option
   number. MAKEPLAY.CMD dynamically creates a playback (script) file that
   holds the appropriate keystrokes to move the highlight to the desired
   option. Here's MAKEPLAY.CMD:
 
     *( MAKEPLAY.CMD--Make a playback file)
     *( to return to the same spot in a)
     *( pull down menu. Expects these values)
     *( to be passed: pull-down number and)
     *( menu option number.)
     SET VAR %1 INT, %2 INT, vplay TEXT
     IF %1 IS NULL OR %2 IS NULL THEN
       WRITE 'You must pass these parameters:'
       WRITE '    The pull-down number'
       WRITE '    Menu option number'
       RETURN
     ENDIF
     SET VAR vpull_num INTEGER = (.%1 - 1), +
       vmenu_num INTEGER = (.%2 - 1), vright = (CHAR(0) + CHAR(77)), +
       vdown = (CHAR(0) + CHAR(80))
     WHILE vpull_num > 0 THEN
       SET VAR vplay = (.vplay + .vright), vpull_num = (.vpull_num - 1)
     ENDWHILE
     WHILE vmenu_num > 0 THEN
       SET VAR vplay = (.vplay + .vdown), vmenu_num = (.vmenu_num - 1)
     ENDWHILE
     SET VAR vplay = (.vplay + (CHAR(0) + CHAR(95)))
     OUTPUT playit.scp
     WRITE .vplay
     OUTPUT SCREEN
     CLEAR VAR vpull_num, vmenu_num, vright, vdown, vplay
     RETURN
 
   Use the PLAY command to execute PLAYIT.SCP right before the CHOOSE
   statement. Then delete PLAYIT.SCP at the end of the application. Below
   is a portion of an .APP file created by Application EXPRESS. The
   arrows show you where to insert the appropriate PLAY, RUN, and DELETE
   commands to implement MAKEPLAY in an Application EXPRESS application.
   Use CODELOCK to make a new .APX procedure file from the modified .APP
   file.
 
     $COMMAND
     MAKEPLAY
     SET QUOTE = '
     SET MESSAGES ON
     CONNECT makeplay
     SET ERROR MESSAGES ON
     NEWPAGE
     SET COLOR WHITE ON BLUE
     SET BELL OFF
     LABEL LBEG1
       NEWPAGE
       PLAY playit.scp
       CHOOSE PICK1 FROM Main IN +
         makeplay.apx AT 1 1 BLACK ON GRAY
       SET VAR PICK11 = (SSUB(PICK1,1))
       SET VAR PICK12 = (SSUB(PICK1,2))
       CLEAR VAR PICK1
       SWITCH (.PICK11)
       CASE 1
         SWITCH (.PICK12)
         CASE 'Option 1'
           NEWPAGE
           SELECT  +
             * +
           FROM  A_Table
           WRITE 'Press any key to continue. '
           PAUSE
           RUN makeplay.cmd USING .PICK11, 1
           BREAK
         CASE 'Option 2'
           NEWPAGE
           SELECT  +
             * +
           FROM  A_Table
           WRITE 'Press any key to continue. '
           PAUSE
           RUN makeplay.cmd USING .PICK11, 2
           BREAK
         ENDSW
         BREAK
           .
           .
           .
     DEL playit.scp
     RETURN
 
   The variable PICK11 always contains the correct number of options on
   the menu bar, so you need only change the second parameter passed to
   MAKEPLAY.CMD to reflect the pull-down option number.
 
 
   Make Red-bar Error Messages
   """""""""""""""""""""""""""
   R:BASE 3.1 displays a red bar at the bottom of the screen to alert the
   user of error messages, information prompts, and rules violations. To
   add red-bar error messages to your own applications, use REDERROR.CMD
   (listed below), or use an undocumented PAUSE feature.
 
   The undocumented PAUSE feature automatically puts "Press any key to
   continue." in a red bar message at the bottom of the screen. All you
   need to do is put a space and then any character after the PAUSE
   command. For example, this works:
 
     PAUSE red
 
   When you press a key to continue, R:BASE clears the screen and
   continues..
 
   REDERROR.CMD is more flexible in that it centers any message in a red
   bar at the bottom of the screen. When you run it, pass it the message
   you want to display by using this syntax:
 
     RUN rederror.cmd USING 'This is the error message.'
 
   Here's REDERROR.CMD
 
     *( REDERROR.CMD--Center message in)
     *( a red bar at the bottom of the screen.)
     SET VAR vmsg=(CTR(.%1,78) + CHAR(255))
     SET VAR vmsg2= (CTR('Press any key to continue.',78) + CHAR(255))
     SNAP error.$$$ FROM 24 1 TO 25 80
     WRITE .vmsg AT 24,1 gray ON red
     WRITE .vmsg2 AT 25,1 gray ON red
     PAUSE
     DISPLAY error.$$$ AT 24
     DEL error.$$$
     CLEAR VAR vmsg, vmsg2, %1
     RETURN
 
 
   How REDERROR.CMD Works
   """"""""""""""""""""""
   First, REDERROR.CMD checks to see if a message was passed to it. Then
   it centers the message in 78 characters and adds a hard blank (ALT
   255) to the end of it to make sure the color spans the entire screen.
 
   Next, REDERROR.CMD uses the SNAP command to save any text that's
   currently displayed on lines 24 and 25. Then it uses two WRITE
   statements to display the desired message with "Press any key to
   continue" below it. The PAUSE command halts processing to wait for the
   user to press a key.
 
   To complete the routine, DISPLAY restores any text that previously was
   on lines 24 and 25. Then REDERROR.CMD deletes the scratch file and
   clears the variables used in the routine.