Link to home
Start Free TrialLog in
Avatar of Mango2
Mango2

asked on

halt your application

Suppose, i have two to command button "cmdGO" and "cmdStop". when i click cmdGo it will run my application but when i click cmdStop to stop the applicaion right then, it wont let me, i have to wait until it goes through all the code in cmdGO. Is there any way to stop the running code right then(like it does when you hit Ctrl+Break. Can any one help me Please?
ASKER CERTIFIED SOLUTION
Avatar of Hornet241
Hornet241
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dankennedy
dankennedy

What code do you have in your cmdStop button to make it stop? And do you want the whole program to stop right away? If so, have you tried just using End?
yes using End will cause the program to STOP, right then and there....kind of like smashing a car into a brick wall to make it stop, right then and there.  Both however have a bad effect on whatever happens to be going on at the time - for the program, if there are any other resources that are involved, such as other files being open, they REMAIN OPEN, or remin in use.  And for the car, the method of stopping is rather harmful to the presumed occupants of the car at the time.

Hornet241's approach is a much better path to pursue.

AW
Avatar of Mango2

ASKER

Thanks guys, I tried with having a END, but it will terminate the program only after the cmdGo procedure is done.  cmdGo  procedure takes around 30 second to finished its job. It interacts with some other application where it retrieves its data. Once the cmdGO is in process it wont even let me click any other button. Even if i click cmdStop button it will wait for the cmdGO to finished it job and then END the application. What i want is to stop the Application right then once cmdStop is clicked. Any Idea?
Like Hornet said, if you put in DoEvents in parts where it could break, or in your loop (if you have one), it should then process the cmdStop button click.

Maybe also try breaking the code in the cmdGo button up, make a couple of different functions which check if a flag is set. This won't stop processing as soon as you hit the button, but it will stop after it's done that section.

Like this...

Private bolFlag as boolean

Private Sub Part1()
if bolFlag then
  < YOUR CODE IN HERE >
end if
End Sub

Private Sub Part2()
if bolFlag then
  < YOUR CODE IN HERE >
end if
End Sub

Private Sub cmdGo_Click()
Call Test1
Call Test2
End Sub