Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit From Infinite Loop Needed

Status
Not open for further replies.

cathalturi

Programmer
Sep 29, 2003
14
DE
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




 
Please always remember that a Windows program is Event-driven.

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.
 
If you really want to follow the infinite looping logic for whatever reason, you will be able to trap keyboard entries and not any buttons in the following manner.

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
 
Hi,

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top