DoEvents 是令程序在忙于执行指令时抽出少许时间让给别的程序。最实用就是若你编了一个死循环的程序,若在循环体中加了 DoEvents 就有时间跳出死循环。如:
dim i,j
for i=1 to 10000
j=j+1
doEvents
next i
这样你试下在程序执行时去运行别的程序。再去掉DoEnents去拟行别的程序就一目了然了。
This example uses the DoEvents function to cause execution to yield to the operating system once every 1000 iterations of the loop. DoEvents returns the number of open Visual Basic forms, but only when the host application is Visual Basic.
' Create a variable to hold number of Visual Basic forms loaded
' and visible.
Dim I, OpenForms
For I = 1 To 150000 ' Start loop.
If I Mod 1000 = 0 Then ' If loop has repeated 1000 times.
OpenForms = DoEvents ' Yield to operating system.
End If
Next I ' Increment loop counter.