?
Solved

halt your application

Posted on 2003-02-26
5
Medium Priority
?
168 Views
Last Modified: 2010-05-01
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?
0
Comment
Question by:Mango2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
Hornet241 earned 225 total points
ID: 8029177
You have to set a global flag on the cmdStop button and then check the flag in the cmdGO code, you also have to let windows process the cmdStop click with the DoEvents()

in the cmdGO sub

cmdGO
Do
    Doevents()
    If cmdStopFlag = True then Exit Sub
    ...
Loop
0
 
LVL 2

Expert Comment

by:dankennedy
ID: 8029209
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?
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8030765
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
0
 

Author Comment

by:Mango2
ID: 8033782
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?
0
 
LVL 2

Expert Comment

by:dankennedy
ID: 8034314
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
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question