Use of Menus for Program Control

Menus provide a powerful means for defining the logic of your program. Wherever you want the flow of your program to follow a choice of paths depending on the user's response, you may use a menu procedure.

If you make the menu procedure a repeat procedure, the user can continue making selections from the menu until the menu is exited, by pressing <Esc> or a menu option that exits from the menu procedure (because you have a condition to repeat that tests return).

Switching Between Subsidiaries

You may sometimes want to select one of several branches at a certain point in your program without using one of the interactive menu types described so far. For example, in a hierarchy of menus an experienced user might be able to bypass the menus by entering a transaction code at the top level of the menu.

The easiest way to do this is to set the force_option variable described below in the field processing of a procedure that precedes each menu. When force_option is set menu and action bar menu procedures will short cut (bypass asking the user to select an option) and automatically return the value of force_option as the selected option. force_option is then reset to 0.

You could use witch between different actions automatically betwee that is, depending only on the results of previous processing. To do this, add a set of subsidiary procedures below the previous procedure and give each a condition to enter to determine whether it is executed.

The standard variable return is especially useful for selecting one (or more) of several possible subsidiaries. In the previous procedure set up the field processing to apply a meaningful value to return. Then set the condition to enter on each subsidiary procedure so that only the appropriate procedure(s) is (are) executed.

Providing an Escape Option

You may create your own escape procedure to ensure that the user performs a particular action before leaving the menu. Set up a procedure having the same option number as the escape option on the menu procedure. This procedure will be executed when the user presses the <Esc> key.

Example: Ask for confirmation before leaving menu

The following procedure tree uses a procedure that allows the user to escape the menu following confirmation:

The procedure body of MENU is set up with the escape option and condition to repeat, by setting the Escape option to 8 and by setting a condition to repeat in the Procedure Overview.

The local field exit_menu is tested in the repeat condition:

not(exit_menu)

The procedure body of CONFIRM is used to check whether the user really wants to leave the menu – the response sets the local field exit_menu.

To set up an escape procedure:

  1. Set up an escape option in the menu procedure
  2. Set up and initialise a local field for use in the repeat condition
  3. Add a condition to repeat which tests the local field
  4. Add an escape procedure
    Set the Link Option number to the escape option number you set up for step 1
  5. Set the local field (see step 2) to the value tested for in the repeat condition of the menu procedure

Test for Option Number

Two standard variables are provided which allow you to test for the last selected menu option. These are:

To test the value of the option selected in a pull down menu, you need to use the following calculation:

(16 * menu number) + pull-down option

For example, where an option is set up on the Link edit as 3/2, for the second option on the third menu, the calculation would be:

 (16 * 3) + 2

This would give the corresponding pull down option for the menu.

Variables used with Menus

The default menu option described under Menu Options can be used to highlight an option. Sometimes, however, you may force a menu option to be executed:

force_option

Set this variable to force an option to be executed in the next menu (or when the current menu is repeated)

end_key
return

These are two different names for the same variable.

In a Combined menu/entry procedure, set this variable to set the option to be selected as though the user had pressed a key. For example, in a POS system, a combined menu entry procedure you might add field processing for end_key that examines the input source, and automatically treats input from a bar code scanner as a request for an item sale, and input from an MSR as a request for payment using a charge card. You may also sometimes want to reset end_key to 0, particularly in interactive proecdures or as part of hot key processing, to prevent a short cut in the next menu.