Results 1 to 2 of 2

Thread: Problem With DoEvents

  1. #1
    Guest

    Lightbulb

    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?

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    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]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width