Is it possible to terminate a loop with an event?

Peter Honey

New Member
Progress has the ability to terminate a loop (DO:, REPEAT: FOR EACH) via keystroke i.e. ON-(ENDKEY,QUIT,STOP)-PHRASE but offers no way to raise these conditions without using keystrokes.

Placing a wait-for within the loop eg.
WAIT-FOR "CHOOSE" OF btn_cancel PAUSE 0.
causes huge delays.

Is there any other way to accomplish this.

Thanx
 

Chris Kelleher

Administrator
Staff member
Peter-

I believe that you are looking for the PROCESS EVENTS statment. Here is some sample code:

<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
DEFINE BUTTON stop-it LABEL "STOP".
DEFINE VARIABLE i AS INTEGER.
DEFINE VARIABLE stop-sel AS LOGICAL INITIAL FALSE.
DISPLAY stop-it.

ON CHOOSE OF stop-it
stop-sel = TRUE.

ENABLE stop-it.

DO i = 1 TO 1000:
DISPLAY i VIEW-AS TEXT.

PROCESS EVENTS.

IF stop-sel
THEN LEAVE.
END.
[/code]

On each pass through the loop, the procedure displays the new value of i and then checks whether any events are waiting to be processed. If no events have occurred, execution continues and the loop iterates. If the STOP button has been chosen, that event is processed changing the value of stop-sel. When execution continues, the program exits the loop.

If the loop does not contain the PROCESS EVENTS statement, the choose event never processes and the loop iterates until i equals 1,000.

Hope this helps.

-Chris

------------------
Chris Schreiber
ProgressTalk.com Manager
chris@fast4gl.com
 
Top