After you display data, the CHOOSE statement moves a highlight bar among a series of choices and selects a choice when you press GO, RETURN, or enter a unique combination of initial characters.
This statement is supported only for backward compatibility.
CHOOSE { { ROW field [ HELP char-constant ] } | { FIELD { field [ HELP char-constant ] } ...} } [ AUTO-RETURN ] [ COLOR color-phrase ] [ GO-ON ( key-label ... ) ] [ KEYS char-variable ] [ NO-ERROR ] [ PAUSE expression ] { [ frame-phrase ] } |
You can specify the AUTO-RETURN, COLOR, GO-ON, KEYS, NO-ERROR, and PAUSE options in any order.
If you use the ROW option with the CHOOSE statement, use the SCROLL statement as well. See the SCROLL statement reference entry examples.
If you use ROW, you can add a COLOR statement to control the video display highlighting.
{ NORMAL | INPUT | MESSAGES | protermcap-attribute | dos-hex-attribute | { [ BLINK- ] [ BRIGHT- ] [fgnd-color] [ bgnd-color ] } | { [ BLINK- ] [ RVV- ] [ UNDERLINE- ] [ BRIGHT- ] [ fgnd-color ] } | VALUE ( expression ) } |
For more information on color-phrase, see the COLOR phrase reference entry.
If you use the NO-ERROR option and the user presses an invalid key, the CHOOSE statement ends. At this point, you usually want to use the LASTKEY function to test the value of the last key the user pressed and then take the appropriate action.
Note that the NO-ERROR option of the CHOOSE statement does not have any affect on the ERROR-STATUS system handle.
The time-out period begins before the user's first keystroke and is reset after each keystroke. If CHOOSE times out, the value of LASTKEY is -1. Use the time-out period to prevent inactivity.
If your procedure might eventually run on a spacetaking terminal, use the ATTR-SPACE option for the CHOOSE statement. Omitting this option makes the highlight bar invisible.
The following procedure displays a strip menu with four choices. The procedure defines two arrays; one holds the items for selection on the menu, the other holds the names of the programs associated with the menu selections. The CHOOSE statement allows the user to select an item from the strip menu. The AVM finds the number (within the array) associated with the item selected and the program associated with that number in the proglist array. The AVM runs the program, if it exists, and displays a message. It also allows the user to select another item if the program does not exist. (In your own application, you associate actions with items selected by the CHOOSE statement.)
r-chsmnu.p
DEFINE VARIABLE menu AS CHARACTER NO-UNDO EXTENT 4 FORMAT "x(7)" INITIAL [ "Browse", "Create", "Update", "Exit" ]. DEFINE VARIABLE proglist AS CHARACTER NO-UNDO EXTENT 4 INITIAL [ "brws.p", "cre.p", "upd.p", "exit.p"]. FORM "Use the sample strip menu to select an action." WITH FRAME instruc CENTERED ROW 10. REPEAT: VIEW FRAME instruc. DISPLAY menu WITH NO-LABELS ROW 21 NO-BOX ATTR-SPACE FRAME f-menu CENTERED. HIDE MESSAGE. CHOOSE FIELD menu GO-ON (F5) AUTO-RETURN WITH FRAME f-menu. IF SEARCH(proglist[FRAME-INDEX]) = ? THEN DO: MESSAGE "The program" proglist[FRAME-INDEX] "does not exist.". MESSAGE "Please make another choice.". END. ELSE RUN VALUE(proglist[FRAME-INDEX]). END. |
The GO-ON option sets the GET key to perform an action like GO. With the LASTKEY function, you could check for F5 and take another action relevant to your application.
Key | NO-ERROR | Action |
---|---|---|
Valid cursor motion1 | N/A | Clear saved keys and move highlight bar. |
Invalid cursor motion2 | NO | Clear saved keys and beep terminal. |
Invalid cursor motion2 | YES | Clear saved keys and return control to procedure. |
A non-unique string followed by an alphanumeric character that does not form a matchable string3 | NO | Clear saved keys and try to match the last key entered. If no match is available then beep terminal. |
A non-unique string followed by an alphanumeric character that does not form a matchable string with the other characters | YES | Return control to procedure. |
An invalid string | NO | Beep terminal. |
An invalid string | YES | Return control to the procedure and, if the KEYS option was used, save any printable keys. |
Other keys4 | NO | Beep terminal. |
Other keys4 | YES | Return control to procedure. |
r-chs1.p
DEFINE VARIABLE abc AS CHARACTER NO-UNDO FORMAT "x(3)" EXTENT 42. DEFINE VARIABLE ix AS INTEGER NO-UNDO. DO ix = 1 TO 42: abc[ix] = STRING(ix, ">9"). END. DISPLAY abc NO-LABELS WITH ATTR-SPACE CENTERED ROW 4 TITLE " CHOOSE STATEMENT " FRAME f-choose WIDTH 36. DISPLAY "Enter your selection " WITH CENTERED NO-BOX FRAME f-instruct. PAUSE 1 BEFORE-HIDE NO-MESSAGE. REPEAT: HIDE MESSAGE. CHOOSE FIELD abc AUTO-RETURN WITH FRAME f-choose. MESSAGE "You selected -> " FRAME-VALUE. END. |
Once you run this procedure, your window looks like the following: