I have a function with a number of long loops. While the function is
running, I want to be able to click a Stop button and exit the function as
quickly as possible.
The abbreviated code looks like this:
[code in form frm1]
Private Sub cmdStart_Click
Call bas1.LongLoops( parameter1, parameter2, parameterN)
End Sub
[code in standard module bas1]
Public Function LongLoops(param eter1, parameter2, parameterN)
Do While i < 10000
[code omitted]
Loop
Do While i < 20000
[code omitted]
Loop
'etc, etc...
End Function
Should I use a static variable?
[code in form frm1]
Private Sub cmdStop_Click
blnStop = True
Call bas1.LongLoops( blnStop, parameter2, parameterN)
End Sub
[code in standard module bas1]
Public Function LongLoops(blnSt op, parameter2, parameterN)
Static blnExit as Boolean
blnExit = blnStop
Do While i < 10000
If blnExit Then Exit Do
[code omitted]
Loop
Do While i < 20000
If blnExit Then Exit Do
[code omitted]
Loop
'etc, etc...
End Function
Or should I just raise an error that causes the function to exit?
[code in form frm1]
Private Sub cmdStop_Click
blnStop = True
Call bas1.LongLoops( blnStop, parameter2, parameterN)
End Sub
[code in standard module bas1]
Public Function LongLoops(blnSt op, parameter2, parameterN)
If blnStop Then Err.Raise MYCUSTOMERROR
Do While i < 10000
[code omitted]
Loop
Do While i < 20000
[code omitted]
Loop
'etc, etc...
End Function
If I raise an error with a second call to the function, will the process
from the first call continue running?
Other options?
Thanks in advance.
running, I want to be able to click a Stop button and exit the function as
quickly as possible.
The abbreviated code looks like this:
[code in form frm1]
Private Sub cmdStart_Click
Call bas1.LongLoops( parameter1, parameter2, parameterN)
End Sub
[code in standard module bas1]
Public Function LongLoops(param eter1, parameter2, parameterN)
Do While i < 10000
[code omitted]
Loop
Do While i < 20000
[code omitted]
Loop
'etc, etc...
End Function
Should I use a static variable?
[code in form frm1]
Private Sub cmdStop_Click
blnStop = True
Call bas1.LongLoops( blnStop, parameter2, parameterN)
End Sub
[code in standard module bas1]
Public Function LongLoops(blnSt op, parameter2, parameterN)
Static blnExit as Boolean
blnExit = blnStop
Do While i < 10000
If blnExit Then Exit Do
[code omitted]
Loop
Do While i < 20000
If blnExit Then Exit Do
[code omitted]
Loop
'etc, etc...
End Function
Or should I just raise an error that causes the function to exit?
[code in form frm1]
Private Sub cmdStop_Click
blnStop = True
Call bas1.LongLoops( blnStop, parameter2, parameterN)
End Sub
[code in standard module bas1]
Public Function LongLoops(blnSt op, parameter2, parameterN)
If blnStop Then Err.Raise MYCUSTOMERROR
Do While i < 10000
[code omitted]
Loop
Do While i < 20000
[code omitted]
Loop
'etc, etc...
End Function
If I raise an error with a second call to the function, will the process
from the first call continue running?
Other options?
Thanks in advance.
Comment