Highlighted
Absent Member.
Absent Member.
1390 views

[archive] Accept Event On Exception?

[Migrated content. Thread originally posted on 29 October 2007]

Has anyone used this phrase before? I could use some help with the syntax.

I've got a COM object that handles all UI and I want the program to remain in Accept mode until something in the code forces it to end.

I'm currently using the following code snippet, which works but causes the object to lose focus every 10 seconds (as the ACCEPT EVENT loop cycles).

Display-Menu.
    CREATE MenuObject
               HANDLE IN MENU-HANDLE
               EVENT PROCEDURE Menu-Events.
    MOVE "N" TO CLOSE-OBJECT, RUN-SOMETHING.
    PERFORM UNTIL CLOSE-OBJECT = "Y"
         ACCEPT EVENT BEFORE TIME 1000 END-ACCEPT
         IF RUN-SOMETHING = "Y"
           MOVE "N" TO RUN-SOMETHING
           PERFORM Execute-Selection
         END-IF
    END-PERFORM.
    DESTROY MENU-HANDLE.

Menu-Events.
    IF EVENT-TYPE = MSG-AX-EVENT
      EVALUATE EVENT-DATA-2
          WHEN MenuItemClick
              MOVE "Y" TO RUN-SOMETHING
          WHEN MenuLogout
              MOVE "Y" TO CLOSE-OBJECT
          WHEN MenuRefresh
              PERFORM Reload-Menu   
      END-EVALUATE.



I'm thinking that using the ON EXCEPTION phrase instead of BEFORE TIME will allow me to control when the ACCEPT EVENT phrase terminates, but I can't figure out how to manage the exception.

Here's a code snippet of what I'd like to do, but I don't know how to control the exception. If I use this code the program hangs.

     01 STOP-ACCEPT                 PIC 999.

     MOVE ZERO TO STOP-ACCEPT.
     PERFORM UNTIL CLOSE-OBJECT = "Y"
         ACCEPT EVENT
              ON EXCEPTION STOP-ACCEPT CONTINUE
         END-ACCEPT
         IF RUN-SOMETHING = "Y"
           MOVE "N" TO RUN-SOMETHING
           PERFORM Execute-Selection
         END-IF
    END-PERFORM.
    DESTROY MENU-HANDLE.

Menu-Events.
    IF EVENT-TYPE = MSG-AX-EVENT
      EVALUATE EVENT-DATA-2
          WHEN MenuItemClick
              MOVE "Y" TO RUN-SOMETHING
              MOVE 27 TO STOP-ACCEPT
          WHEN MenuLogout
              MOVE "Y" TO CLOSE-OBJECT
              MOVE 27 TO STOP-ACCEPT
          WHEN MenuRefresh
              PERFORM Reload-Menu   
      END-EVALUATE.


I can't find any examples of this syntax in the documentation or on the AcuCorp website or forum. Can anyone provide an example of how this can be done?

Thanks!
Laura
0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Accept Event On Exception?

I wasn't able to figure out how to terminate an ACCEPT EVENT statement using the ON EXCEPTION clause. Instead, I'm using ACCEPT OMITTED ON EXCEPTION and using the W$KEYBUF routine to force exception keystrokes in the keyboard input buffer. 😄

Here's some sample code:

01 STOP-ACCEPT            PIC 999.
   03 SELECT-KEY           VALUE 100.
   03 LOGOFF-KEY           VALUE 200.

Display-Menu.
    CREATE MenuObject
               HANDLE IN MENU-HANDLE
               EVENT PROCEDURE Menu-Events.
    * Remap the CTRL-T and CTRL-Y keys to match the hard-code exception values
    SET ENVIRONMENT "KEYSTROKE" TO "Exception=100 ^T".
    SET ENVIRONMENT "KEYSTROKE" TO "Exception=200 ^Y".
    MOVE ZERO TO STOP-ACCEPT.
    PERFORM Accept-Menu UNTIL LOGOFF-KEY.
    DESTROY MENU-HANDLE.

Accept-Menu.
    MOVE ZERO TO STOP-ACCEPT.
    ACCEPT OMITTED
          ON EXCEPTION STOP-ACCEPT
              IF SELECT-KEY OR LOGOFF-KEY
                 NEXT SENTENCE
              END-IF
    END-ACCEPT.
    CALL "W$KEYBUF" USING 3.
    IF SELECT-KEY
       PERFORM Execute-Selection.

Menu-Events.
    IF EVENT-TYPE = MSG-AX-EVENT
      EVALUATE EVENT-DATA-2
          WHEN MenuItemClick
              CALL "W$KEYBUF" USING 2, "{^T}"
          WHEN MenuLogout
              CALL "W$KEYBUF" USING 2, "{^Y}"
          WHEN MenuRefresh
              PERFORM Reload-Menu   
      END-EVALUATE.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Accept Event On Exception?

To terminate an ACCEPT from an event procedure Set EVENT-ACTION to EVENT-ACTION-TERMINATE
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.