Exit From Infinite Loop Needed
Exit From Infinite Loop Needed
(OP)
I'm trying to have a loop check the comport at least once a second in an infinite loop. I would like to stop the loop by pressing a button on the same window. Addtionaly exiting via the ESC key would be great.
I've tried numerous variations. Either the loop can't be interrupted or it will only run when the 'Stop' key / button is pressed.
Although this may sound trivial - it's got me puzzled.
My example: ( The String-Counter is a substitute for the comport check)
QS_StopButton = 0
QS_TestString = 0
LOOP UNTIL KEYCODE() = EscKey
IF QS_StopButton = 1 THEN BREAK.
QS_TestString = QS_TestString + 1
DISPLAY()
END
Pressing the STOP button will asign QS_StopButton = 1
I've tried numerous variations. Either the loop can't be interrupted or it will only run when the 'Stop' key / button is pressed.
Although this may sound trivial - it's got me puzzled.
My example: ( The String-Counter is a substitute for the comport check)
QS_StopButton = 0
QS_TestString = 0
LOOP UNTIL KEYCODE() = EscKey
IF QS_StopButton = 1 THEN BREAK.
QS_TestString = QS_TestString + 1
DISPLAY()
END
Pressing the STOP button will asign QS_StopButton = 1
RE: Exit From Infinite Loop Needed
So the way to do it would be to define the Timer attribute on the Window properties to 6000 i.e. 1 minute. In the Event:Timer embed of the Window write the code to do the needful checking. You can create a push button on the window to stop or exit or do whatever u want.
RE: Exit From Infinite Loop Needed
LOOP !... your loop
Stop# = False
LOOP UNTIL KEYBOARD() !Wait for any key
ASK
IF KEYCODE() = EscKey
Stop# = True ; BREAK
END
END
IF Stop# THEN BREAK.
END !... end of your loop
RE: Exit From Infinite Loop Needed
If I had to do this then I would use ACCEPT.
In my main window I would do :
ThreadNo = Start(MyComProcess)
To stop it I would do on a button :
Post(Event:closeWindow,,ThreadNo)
and in myComProcess I would have :
WindowWait WINDOW('Caption'),AT(-1,-1,0,0),GRAY,Timer(100)
END
CODE
Accept
If Event() = Event:Timer
CheckComport
End
If Event() = Event:CloseWindow
Break
End
End
Close(WindowWait)
that works great.
Valery.