What does “DoEvents” do in vb6?

后端 未结 4 1379
太阳男子
太阳男子 2020-12-11 00:18

What does \"DoEvents\" do in vb6 ? Why do I get the error message \"Out of stack space\" ? What does it mean ?

4条回答
  •  遥遥无期
    2020-12-11 01:08

    As stated else where, DoEvents allows other events in your application to fire. Here's an example of how you can use DoEvents without the "Out of stack space" issue. This makes sure you don't run through the code multiple times by using a Boolean to indicate the code is running.

    Sub Example()
        'Create static variable to indicate the sub is running.
        Static isRunning As Boolean
        'Exit the sub if isRunning
        If isRunning Then Exit Sub
        'Indicate sub is running
        isRunning = True
        'Sub does stuff
        DoEvents
        'Ends up calling sub again
        Example 'Added just to prove via testing.
        'Indicate sub is no longer runningrunning
        isRunning = False
    End Sub
    

提交回复
热议问题