How to abort a tight loop
I have a class module that processes image data. It may process hundreds or thousands of images per pass. Once I call the go method I want to be able to abort the process. I thought I could add a property called abort and check for it each loop. If true I would terminate the loop. I have a command button on the form that calls the class called abort. It just sets the classes abort property to true. I have also included a DoEvents in the loop so the button click gets processed. This works fine but the abort property never gets set. If I check a control on the form from the class for abort (say an abort check box) rather than looking at the abort propery it works.
Any ideas how to abort a class method reliably without external controls?
Thanks
Craig
Re: How to abort a tight loop
I believe this is what you said you tried, but just to be sure
In a form:
option Explicit
Dim oLoop as LoopObject
private Sub Command1_Click()
oLoop.Cancel = true
End Sub
private Sub Command2_Click()
set oLoop = new LoopObject
oLoop.Looper
End Sub
In a class module...
option Explicit
Dim bCancel as Boolean
public property let Cancel(b as Boolean)
bCancel = b
End property
public Sub Looper()
Do While Not bCancel
DoEvents
Loop
End Sub
This should work.