Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Exit From Infinite Loop Needed

Exit From Infinite Loop Needed

Exit From Infinite Loop Needed

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

     IF QS_StopButton = 1 THEN BREAK.
     QS_TestString = QS_TestString + 1

Pressing the STOP button will asign QS_StopButton = 1

RE: Exit From Infinite Loop Needed

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.

RE: Exit From Infinite Loop Needed

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
     IF KEYCODE() = EscKey
        Stop# = True ; 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 :


and in myComProcess I would have :

WindowWait WINDOW('Caption'),AT(-1,-1,0,0),GRAY,Timer(100)

      If Event() = Event:Timer
      If Event() = Event:CloseWindow

that works great.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close