Private Function delay(mins%, secs%, Optional ByRef stopflag) As Long
'ムモハアコッハ
On Error Resume Next
Dim endofdelay
endofdelay = DateAdd("n", mins, Now)
endofdelay = DateAdd("s", secs, endofdelay)
delay = 0
Do While (Now < endofdelay)
DoEvents
If Not IsMissing(stopflag) Then
If stopflag Then
delay = 1
stopflag = False
Exit Do
End If
End If
Loop
Sub play_fireSound1(ByVal n As Integer)
Dim Start As Long
Dim I As Integer
For I = 1 To fire_floor_count
Start = Timer
SoundFileName$ = App.Path & "\sound\" + CStr(fire_floor_num(I)) + ".wav"
sndPlaySound SoundFileName$, Flags&
Do While Timer < Start + 3 ' 3 秒的延时
DoEvents
Loop
Next I
做一个延迟的小程序
Gettickcount是一个asp函数,表示是自电脑开机以来所经历的时间
Declare Function GetTickCount Lib "kernel32" () As Long ‘声明函数
public function time_delay (nowtime as long ,timelong as long )
do
doevents
loop until abs(gettickcount-nowtime)>timelong
end function
建好模块 然后引用该函数,如下所示:
Dim time_tep as long
Time_tep=50
Call time_delay (gettickcount,time_tep) ‘延迟50毫秒
最标准的是这个,可以精确到毫秒:
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Dim SaveTime As Double
Dim OverTime As Long
OverTime = 2000 '延迟2000毫秒
SaveTime = timeGetTime '记下开始时的时间
Do Until timeGetTime - SaveTime >= OverTime '延迟
DoEvents
Loop