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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User prompted "Stop" while executing code.

Status
Not open for further replies.

TomPose

Technical User
Dec 2, 2002
25
0
0
US
I am trying to stop the execution of code with a keypress. I seem to have runaway code and can not determine why. I need to be able to stop the code from executing by pressing a key during the execution. The ctrl-break does not work, so I want to use something similar to Basic's A$=inkey$. Any ideas?
 
Wouldn't you be better off in fixing the runaway code?

If you post your code, maybe someone here can offer a fix.
 
CaptainD is right, fix the problem code, but in the meantime, you can try adding DoEvents statement in the code where you think it might be looping to allow a manual break.

"Retired Programmer". So, please be patient.
 
yes, thanks Cap'y dog... I am trying to fix the code - perhaps you could tell me where the problem is. As far as posting the code, it is rather long and I don't know which part is failiing.


MoLaker,

I do not know where to put the break? I would like to have a way to stop the code by key press, but don't know where to put the stop button. Is it possible to make a stop happen by setting up a "Ctrl-break" type function that will actually work when pressed - unlike the "Ctrl-Break"? When I try to put a stop/break in manually, the runaway doesn't happen, or the loop that it gets stuck in is not apparent and is part of another function call.
 
Try putting some debug break points in at strategic locations (at the beginning of steps where a runaway might occur), then step through until you hit the runaway point. You might be able to narrow it down using this method. Actually, "runaway" might not be what is happening. It might be just waiting on a response somewhere. Look for typical runaway or looping procedures - Do While/Do Until, etc. or possibly if you have any file system procedures where the application might be waiting on a response. If you have an On Error statement, temporarily rem it out in case there is an error causing the problem.

"Retired Programmer". So, please be patient.
 
TomPose said:
it is rather long and I don't know which part is failiing.
That right there may be the root of the problem. When we make very long monolithic functions debugging becomes very difficult.

I try to follow the Code Complete philosophy of making very short, highly specialized functions. Try to break the work down into many small subroutines. It makes tracking down bugs such as infinite loops easier (in such a case, you would just keep "stepping over" the subroutines until you find the one that never returns control).

If you go through the exercise of breaking up your subroutine in smaller pieces, during the process the source of your problem may become clear (it's kind of the same as cleaning your house when you are looking for something). Plus you are left with more manageable code at the end of the exercise.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top