Kbase 13999: How to set default value on CHOOSE statement ( use KEYS )
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/10/1998 |
|
How to set default value on CHOOSE statement ( use KEYS )
4GL programmers often want to indicate a default selection for a
CHOOSE statement. The default may depend on information within their
application. To do this, they must create a character variable which
holds the corresponding keystroke for the default selection and set
that variable to the keystroke before executing the CHOOSE statement
with the KEYS option.
DEFINE VARIABLE menu AS CHARACTER EXTENT 4 FORMAT "x(7)"
INITIAL [ "Browse", "Create", "Update", "Exit" ].
DEFINE VARIABLE proglist AS CHARACTER EXTENT 4
INITIAL [ "brws.p", "cre.p", "upd.p", "exit.p"].
DEFINE VARIABLE i AS INTEGER.
FORM "Use the sample strip menu to select an action."
WITH FRAME instruc CENTERED ROW 10.
/* this will set default to "U"pdate program selection */
DEFINE VARIABLE savekey AS CHARACTER INITIAL "U".
REPEAT:
VIEW FRAME instruc.
DISPLAY menu WITH NO-LABELS ROW 21 NO-BOX ATTR-SPACE FRAME f-menu
CENTERED.
HIDE MESSAGE.
/* The KEYS option will set the default based on the current value
of the savekey variable. Any keystrokes from the user
will be stored into savekey and can be examined. */
CHOOSE FIELD menu GO-ON (F5) KEYS savekey WITH FRAME f-menu.
MESSAGE "savekey = " savekey. PAUSE.
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.
NOTE: Using the AUTO-RETURN option re-initializes the KEYS character
variable.
Refer also to the Language Reference documentation for the CHOOSE
statement and the KEYS option.
Progress Software Technical Support Note # 13999