A user Stop Button

Daveyk01

Registered User.
Local time
Today, 13:19
Joined
Jul 3, 2007
Messages
144
What is the best way to provide the user with a stop button? This isincase the code gets stuck in a loop, not from programming error necassarily but from external influence.

For example the program controls an instrument which responds, your program takes a reading and tells the instrument to adjust slightly and then takes another reading, etc. In my case, my program is doing a two point calibration on an electroni instrument, so there is a lot of back and forth adjusting of a low end control and a high end control until they are both perfectly balanced. I had an instance where I bumped a control on the instrument while this rouinte was running, the routine never recovered and stuck in this calibration loop. I had the code envirement loaded so all I had to do was clcik the "STOP (.)" button. The end user, typically, would not have this luxury. I found the STOP statement brings up the code environment and that is not desireable, I am not sure what it would do if compile to an MDE statement.

I have put in a tries counter that allows the program to "give up" after a while, but that may not be ideal.

Of course a close form button stops execution, but then the user will loose data collected on the screen before having a chance to save it.

What is normally done in Access VBA for an E-STOP button?
 
Invoking DoEvents from inside the loop might be the simplest solution if a button is available to the user... Roughly...

Code:
Private Halt As Boolean

Sub LoopBlah

  Do Loop
    Do Something
    DoEvents
    If Halt = True Then
       Exit Loop
    End If
  Loop

End Sub

Sub Button_Click

  Halt = True

End Sun

If you can't programmatically detect an exception, the last catch is the timeout you wrote about.

Regards,
Tim
 

Users who are viewing this thread

Back
Top Bottom