Release 10.1A: OpenEdge Development:
Programming Interfaces

> ## Telling Progress how to continue processing

> When you modify a field or variable, pressing GO tells Progress to accept the data in all the modified fields and variables in the current statement and to go on to the next statement in the procedure.

> As the following figure shows, if you press GO while the cursor is in the name, credit–limit, or sales–rep fields, Progress continues on to the next statement in the procedure, which is `END`. The procedure then returns to the beginning of the `FOR` `EACH` loop.

> i-intro.p

> You might want to define function keys that tell Progress to continue processing data a certain way. You can use the `GO–ON` phrase with the `SET` or `UPDATE` statement to do this, as shown in the following procedure:

> i-gon1.p
>     DISPLAY "You may update each customer." SKIP
>             "After making your changes, press one of:" SKIP(1)
>             KBLABEL("GO") + "  - Make the change permanent" FORMAT "x(40)"
>                SKIP
>             KBLABEL("END-ERROR") + "  - Undo changes and exit" FORMAT "x(40)"
>                SKIP
>             "F8  - Undo changes and try again" SKIP
>             "F10 - Find next customer" SKIP
>             "F12 - Find previous customer"
>     WITH CENTERED FRAME ins.
>     FIND FIRST Customer.upd-loop:
>     REPEAT:
>        UPDATE Cust-num Name Address Address2 City St
>             GO-ON(F8 F10 F12) WITH 1 DOWN CENTERED.
>        CASE LASTKEY:
>           WHEN KEYCODE("F8") THEN
>              UNDO upd-loop, RETRY upd-loop.
>           WHEN KEYCODE("F10") THEN
>              FIND NEXT Customer.
>           WHEN KEYCODE("F12") THEN
>              FIND PREV Customer.
>        END CASE.
>     END.

> In this example, if the user presses F8, F10, or F12 while updating the customer data, the procedure immediately goes on to the next statement in the procedure. Let’s take a closer look at this procedure.

> Any key you can press while running a Progress procedure has a code, a function, and a label associated with it. The code of a key is an integer value that Progress uses to identify that key. For example, the code of F1 is 301. The function of a key is the work that Progress does when you press the key. For example, the function of the F1 key may be `HELP`. The label of a key is the actual label that appears on the keyboard key. The label of the F1 key is F1.

> As shown earlier, you can use the `KEYLABEL`, `KEYCODE`, `KEYFUNCTION`, and `KBLABEL` functions to convert key labels, key codes, and key functions. In addition to these functions, the `LASTKEY` function returns the key code of the last key pressed.

> You can use the functions described in this table to monitor the keys being pressed, as in this example:

> i-keys.p
>     REPEAT:
>       DISPLAY "Press any key".
>       READKEY.
>       DISPLAY LASTKEY LABEL "Key Code"
>               KEYLABEL(LASTKEY) LABEL "Key Label"
>               KEYFUNCTION(LASTKEY) LABEL "Key Function"
>                                   FORMAT "x(12)".
>       IF KEYFUNCTION(LASTKEY) = "end-error" THEN LEAVE.
>     END.

> Run procedure `i-keys.p` to see how the different keys you press translate into key codes, key labels, and key functions.

> Now, run the `i-gon1.p` procedure. You see a screen similar to the one shown in Figure 4–5.

> Figure 4–5: The i-gon1.p procedure

> While updating the customer information, press F9, F10, F11, or use either of the standard techniques to signal the end of data entry, Progress goes on to the next statement in the procedure. If you press any other key, Progress does not continue on to the next statement in the procedure, but instead performs the data entry operation associated with that key. If you press END-ERROR, Progress performs the default `ENDKEY` processing of `UNDO,` `LEAVE`.

> If Progress does continue on to the next statement in the procedure, the `CASE` statement determines the action to take by checking the value of the last key pressed.

> The procedure `i-gon2.p` shows how you can achieve the same functionality in an event-driven application:

> i-gon2.p
>     FORM
>        Customer.Cust-num Customer.Name Customer.Address
>        Customer.Address2 Customer.City Customer.State
>        WITH CENTERED FRAME upd-frame.
>     DISPLAY "You may update each customer." SKIP
>             "After making your changes, press one of:" SKIP(1)
>             KBLABEL("GO") + "  - Make the change permanent" FORMAT "x(40)"
>                SKIP
>             KBLABEL("END-ERROR") + "  - Undo changes and exit" FORMAT "x(40)"
>                SKIP
>             "F8  - Undo changes and try again" SKIP
>             "F10 - Find next customer" SKIP
>             "F12 - Find previous customer"
>             WITH CENTERED FRAME ins.
>     ON F8 ANYWHERE
>        DO:
>          DISPLAY Customer.Cust-num Name Address City State
>             WITH CENTERED FRAME upd-frame.
>        END.
>     ON F10 ANYWHERE
>        DO:
>          APPLY "GO" TO FRAME upd-frame.
>          FIND NEXT Customer.
>          DISPLAY Cust-num Name Address Address2 City State
>             WITH CENTERED FRAME upd-frame.
>        END.
>     ON F12 ANYWHERE
>        DO:
>          APPLY "GO" TO FRAME upd-frame.
>          FIND PREV Customer.
>          DISPLAY Cust-num Name Address Address2 City State
>             WITH CENTERED FRAME upd-frame.
>        END.
>     ON GO OF FRAME upd-frame
>        ASSIGN FRAME upd-frame Customer.Cust-num Name Address Address2
>               City State.
>     ENABLE ALL WITH FRAME upd-frame.
>     FIND FIRST Customer.
>     APPLY "F8" TO FRAME upd-frame.
>     WAIT-FOR END-ERROR OF FRAME upd-frame.

> Use the `ANYWHERE` option of the `ON` statement to set up triggers that execute no matter which widget has input focus. In `i-gon2.p`, the `ANYWHERE` option is used to assign triggers to function keys.

> Note: In a larger program, you must be careful of the scope of the `ANYWHERE` trigger.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095