Public Sub BKWait(HowManySecs) 'pause for HowManySecs seconds Dim EndWait EndWait = DateAdd("s", HowManySecs, Now) While Now < EndWait 'this is dummy text...nothing is actually done during the wait 'u can also add 'DoEvents' here Wend End Sub
Public Declare Function GetTickCount Lib "kernel32" () As Long
XX = GetTickCount Do While GetTickCount - XX < 200 DoEvents Loop用API还是不错的嘛:)
大家都忘了Timer函数吗?Timer 函数 返回一个 Single,代表从午夜开始到现在经过的秒数。语法Timer说明Microsoft Windows中,Timer函数返回一秒的小数部分。 Timer 函数示例 本示例使用 Timer 函数来暂停应用程序。同时用 DoEvents 在暂停期间将控制让给其他进程。 Dim PauseTime, Start, Finish, TotalTime If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then PauseTime = 5 ' 设置暂停时间。 Start = Timer ' 设置开始暂停的时刻。 Do While Timer < Start + PauseTime DoEvents ' 将控制让给其他程序。 Loop Finish = Timer ' 设置结束时刻。 TotalTime = Finish - Start ' 计算总时间。 MsgBox "Paused for " & TotalTime & " seconds" Else End End If
不能用循环的方法,这样你的资源会很紧张的。 建议用TIMER的方法,但timer最多只能设65536MS,如果要设更长的话,就 在timer的触发事件中写上(timer最好设为允许的最小误差时间的50%,) if now-StartTime<a then doevents else ... endif 这样就比较准确了
'pause for HowManySecs seconds
Dim EndWait
EndWait = DateAdd("s", HowManySecs, Now)
While Now < EndWait
'this is dummy text...nothing is actually done during the wait
'u can also add 'DoEvents' here
Wend
End Sub
XX = GetTickCount
Do While GetTickCount - XX < 200
DoEvents
Loop用API还是不错的嘛:)
返回一个 Single,代表从午夜开始到现在经过的秒数。语法Timer说明Microsoft Windows中,Timer函数返回一秒的小数部分。
Timer 函数示例
本示例使用 Timer 函数来暂停应用程序。同时用 DoEvents 在暂停期间将控制让给其他进程。 Dim PauseTime, Start, Finish, TotalTime
If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then
PauseTime = 5 ' 设置暂停时间。
Start = Timer ' 设置开始暂停的时刻。
Do While Timer < Start + PauseTime
DoEvents ' 将控制让给其他程序。
Loop
Finish = Timer ' 设置结束时刻。
TotalTime = Finish - Start ' 计算总时间。
MsgBox "Paused for " & TotalTime & " seconds"
Else
End
End If
建议用TIMER的方法,但timer最多只能设65536MS,如果要设更长的话,就
在timer的触发事件中写上(timer最好设为允许的最小误差时间的50%,)
if now-StartTime<a then
doevents
else
...
endif
这样就比较准确了