Re: Should be easy one.....
The DoEvents
command let other processes to take place. So, if you place this command to the beginning of your command1_click code, it will give you the chance at any point to stop executing the code by pressing the second button. Of course I suppose that by pressing the second one you may have written code for emptying the memory (such as release recordsets, variables etc). Hope I helped you.
Michael Vlastos
Automation Engineer
Company SouthGate Hellas SA
Development Department
Athens, Greece
Re: Should be easy one.....
So how can I stop DoEvents ..... what is the code to stop it?
Thank you
Re: Should be easy one.....
I think this is what you should be doing (or similar). Take a form with two buttons (cmdStart and cmdStop) and try the following code :
option Explicit
'
private mbQuitLongStuff as Boolean
'
private Sub cmdStart_Click()
'
' Example of doing something very long....
'
Dim l as Long
'
mbQuitLongStuff = false
'
for l = 1 to 10000000
If l Mod 1000 then
DoEvents
End If
If mbQuitLongStuff then
Exit for ' and cleanup afterwards
End If
next
'
If mbQuitLongStuff then
MsgBox "We Quit !"
End If
'
End Sub
'
private Sub cmdStop_Click()
mbQuitLongStuff = true
End Sub
You can change the interval that 'doevents' occurs at in the 'If l Mod...' line. Making 'doevents' happen at shorter intervals will make your loop take longer (but your app will be more responsive). Becareful using this method though, DoEvents allows your app to process messages for other controls (and close the form etc), so make sure that you've disabled all relevant controls before you start the loop and reenable them afterwards.
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
Re: Should be easy one.....
Maybe a little missunderstanding...
DoEvents let you press other buttons and generally to take place asychronous processes. That means that you use DoEvents if you want to be able to stop a long loop, or a loop without end. So, I think I didn't understand you, or you didn't understand me. Sorry if it was my fault.
If you need more explanations, ask me.
Michael Vlastos
Automation Engineer
Company SouthGate Hellas SA
Development Department
Athens, Greece