Hello,
I have two basic buttons:
START and STOP.
When I press START, it takes approximately 5 seconds to perform the process.
However, when I press STOP, it stops after the whole process is done.
Is there a way, I can halt the process during the process?
Thank you.
Process Override
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Process Override
Does your process involve a loop (For ... Next, or Do ... Loop)?
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 61
- Joined: 29 Jul 2010, 14:52
Re: Process Override
Yes. but it also involves lots of other things.
It is recording a data from a machine at a periodic interval.
and it takes approx 5 secs due to timing issues (waiting function)..
It is recording a data from a machine at a periodic interval.
and it takes approx 5 secs due to timing issues (waiting function)..
I don't have one
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Process Override
You can break out of a loop like this:
If you have a Do ... Loop loop, use Exit Do instead of Exit For.
If reading data from the machine is a single action, you cannot interrupt that.
Code: Select all
Public blnStop As Boolean
Private Sub cmdStart_Click()
Dim i As Long
blnStop = False
For i = 1 To 1000
...
...
' Give other things a chance
DoEvents
If blnStop = True Then
Exit For
End If
Next i
End Sub
Private Sub cmdStop_Click()
blnStop = True
End Sub
If reading data from the machine is a single action, you cannot interrupt that.
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 61
- Joined: 29 Jul 2010, 14:52
Re: Process Override
Thank you,
that gave a pretty good idea what I must do.
But it seems I wasn't clear enough (sorry)
I'm having problems clicking the stop button in the first place while the process is running.
How can I make it available for clicking even if there is a process running (not reading but waiting functions and such)..
that gave a pretty good idea what I must do.
But it seems I wasn't clear enough (sorry)
I'm having problems clicking the stop button in the first place while the process is running.
How can I make it available for clicking even if there is a process running (not reading but waiting functions and such)..
I don't have one
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Process Override
Are you using Application.Wait? According to the help file, "The Wait method suspends all Microsoft Excel activity", i.e. you won't be able to click the Stop button until the specified time.
If not, DoEvents should give you a chance to click the Stop button. If that doesn't work, the "waiting functions" cannot be interrupted, so you're out of luck.
If not, DoEvents should give you a chance to click the Stop button. If that doesn't work, the "waiting functions" cannot be interrupted, so you're out of luck.
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 61
- Joined: 29 Jul 2010, 14:52
Re: Process Override
I haven't used Application.Wait thankfully.
So, I'll just implement it and get back to you asa I can :P
Thank you, HansV.
So, I'll just implement it and get back to you asa I can :P
Thank you, HansV.
I don't have one
-
- StarLounger
- Posts: 61
- Joined: 29 Jul 2010, 14:52
Re: Process Override
Haven't tried all of the conditional cases (too many -_-)
but it seems to work jsut fine!
Thank you very much HansV!
but it seems to work jsut fine!
Thank you very much HansV!
I don't have one