Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
1、API Sleep n*1000 例如sleep 2000 延时2秒
2、自己写dim t as single t=timer while timer-t< 时间(单位秒) doevents wend
Public Sub Delay(HowLong As Date) TempTime = DateAdd("s", HowLong, Now) While TempTime > Now DoEvents '让 windows 去处理其他事 Wend End Sub用:Delay 5 调用,延时5秒!
必须得考虑 跨0点 否则你会有大麻烦 Public Sub Wait_S(SecondV As Single) Dim i As Single, j As Single i = Timer + SecondV Do While i > Timer If Timer < 1 And i >= 86400 Then '跨0点处理 i = i - 86400 End If DoEvents Loop End Sub
书上有的,忘了具体是怎么写了,反正是用doevents没错,还得注意0点的跨越,不好意思
'延时以毫秒计算 Public Sub Delay(MSec As Long) Dim tempSec As Long tempSec = Timer() + MSec / 1000 Do While Timer() < tempSec ' DoEvents If Timer() < 1 Then Exit Sub End If Loop End Sub例如:延时200毫秒 Delay 200 延时2秒 Delay 2000
Public Declare Function GetTickCount Lib "Kernel32" () As Long Public Const cnMaxLong = 2147483647 '长整型的最大值'**********过程名:DelayTime****************** '作者: '书写日期:2002.03.25 '编辑日期:2002.03.25 '目的:进行延时 '方法: '应用于:MainMod模块 '注释:lngMSec为要延时的毫秒秒数 '******************************************** Public Sub DelayTime(ByVal lngMSec As Long) Dim lngTimeStart As Long Dim lngInterval As Long
lngTimeStart = GetTickCount Do While lngInterval < IIf(lngInterval >= 0, lngMSec, lngMSec - cnMaxLong) DoEvents lngInterval = GetTickCount - lngTimeStart Loop End Sub================= 共同学习,共同进步
例如sleep 2000 延时2秒
例如sleep 2000 延时2秒
t=timer
while timer-t< 时间(单位秒)
doevents
wend
TempTime = DateAdd("s", HowLong, Now)
While TempTime > Now
DoEvents '让 windows 去处理其他事
Wend
End Sub用:Delay 5 调用,延时5秒!
Public Sub Wait_S(SecondV As Single)
Dim i As Single, j As Single
i = Timer + SecondV
Do While i > Timer
If Timer < 1 And i >= 86400 Then '跨0点处理
i = i - 86400
End If
DoEvents
Loop
End Sub
Public Sub Delay(MSec As Long)
Dim tempSec As Long
tempSec = Timer() + MSec / 1000
Do While Timer() < tempSec
' DoEvents
If Timer() < 1 Then
Exit Sub
End If
Loop
End Sub例如:延时200毫秒
Delay 200
延时2秒
Delay 2000
Public Const cnMaxLong = 2147483647 '长整型的最大值'**********过程名:DelayTime******************
'作者:
'书写日期:2002.03.25
'编辑日期:2002.03.25
'目的:进行延时
'方法:
'应用于:MainMod模块
'注释:lngMSec为要延时的毫秒秒数
'********************************************
Public Sub DelayTime(ByVal lngMSec As Long)
Dim lngTimeStart As Long
Dim lngInterval As Long
lngTimeStart = GetTickCount
Do While lngInterval < IIf(lngInterval >= 0, lngMSec, lngMSec - cnMaxLong)
DoEvents
lngInterval = GetTickCount - lngTimeStart
Loop
End Sub=================
共同学习,共同进步