-
I have a doevents command right before the last line of a loop in my program and i keep getting an error, 'out of stack space.' Is there another function like DoEvents that can keep the program from freezing up while a long loop is executing and not get the out of stack space error?
-
If you get an out of stack space error, I'm pretty sure you have a recursive procedure you didn't know about. I think the DoEvents frees some processor time, so this becomes a problem now.
Unless the loop is started from a timer event, I don't thing the DoEvents caused the problem, but just exposed it. Don't use doevents in combination with timer events, unless you disable the timer in the beginning of the code and enable it at the end.
If you don't have the code started from a timer event, this recursion could come from improper use of some other events.
For instance:
Code:
Private Sub Text1_GotFocus()
Dim x As Long
Text1.Enabled = False
'do some stuff here
Text1.Enabled = True
Text1.SetFocus
' now do some other stuff
x = Timer
While Timer - 2 < x
DoEvents ' this causes another start of Text1_GetFocus
Wend
End Sub
The problem here is not the doevents, it is the recursive calling of Text1_GotFocus, by setting the focus in the GotFocus event.
P.S.
If the error occurs, you can have a look at the call stack, to view where the recursion occurred. Menu: View --> Call Stack
[Edited by Frans C on 05-20-2000 at 04:39 AM]