想调用一个函数等待30秒
再执行下面的语句

解决方案 »

  1.   

    Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
      

  2.   

    或者Sleep
    Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
    单位是毫秒'***********************************
    Public Sub Wait(delay As Single)
        '单位是秒,例如3.5s    starttime! = Timer
        Do Until Timer >= starttime! + delay
        LoopEnd Sub
      

  3.   

    如果精度要求的不是很高的话上面的Wait()函数也就够了。
      

  4.   

    sleep函数就可以。
    用一个循环也可以。
    for i = 0 to 10000
    next
      

  5.   

    楼上的死循环也行,这个函数不错,我用过的。
    Public Sub BKWait(HowManySecs)
        Dim EndWait
        EndWait = DateAdd("s", HowManySecs, Now)
        While Now < EndWait
            '空语句       
        WendEnd Sub
    例如:
       ......
       BKWait(30)
       ......
      

  6.   

    dim i as long
    i=1
    do while i<1000
      DoEvents
    loopDoEvents这个语句在好多别人程序中见过,好像是让程序等待一会儿,具体是待多长时间,我也不清楚。
      

  7.   

    sleep也可以,但是它会让整个程序停滞,不建议使用。最标准的是这个,可以精确到毫秒:
    Private Declare Function timeGetTime Lib "winmm.dll" () As LongDim SaveTime As Double
    Dim OverTime As Long 
    OverTime = 2000 '延迟2000毫秒
    SaveTime = timeGetTime '记下开始时的时间
    Do Until timeGetTime - SaveTime >= OverTime '延迟
       DoEvents
    Loop
      

  8.   

    dime ltime as date
       ltime =Timer()
       While Timer() - ltime <= 20 * 0.05  '延时20×0.05s
       DoEvents
       Wend
      

  9.   


    做一个延迟的小程序
    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毫秒
      

  10.   

    使用循环+DOEVENTS的好处在于可以不打断程序的运行,坏处在于对时间的控制不是很精确,机器不同,等待的时间也不同。使用SLEEP的好处在于时间精确,可以控制到毫秒,坏处在于,程序在此停顿,属于同步等待。使用TIMMER控件的好处在于时间比较精确(约精确到十分之一秒),结合DOEVENTS也可以做到异步。坏处在于在时间要求较高的场合不适用,并且当有一个比较费时的运算在进行时会“失步”。结合上述几个的长处可以使用:循环+doenevts+GetTickCount 即精确又可以做到异步停顿。由于程序比较简单,就不写出来了。
      

  11.   

    sleep(500)   '500毫秒
      

  12.   

    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  
        
    End Sub
    这是播放wav时的时间延迟(3s)DoEvents是转让控制权,以便让操作系统处理其它的事件。不然的话你的整个程序都停在哪儿了!
      

  13.   

    哪位大哥讲讲DoEvents到底是等待多长时间呀?
      

  14.   

    Private Function delay(mins%, secs%, Optional ByRef stopflag) As Long
    '&#65425;&#65427;&#65418;&#65393;&#65402;&#65391;&#65418;&#63729;
    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
        LoopEnd Function
      

  15.   

    写个过程给你:
    Private Declare Function timeGetTime Lib "winmm.dll" () As LongSub Delay(Byval DelayTime As Long) '单位是毫秒
    DelayTime =DelayTime + Timegettime
    Do While Timegettime < DelayTime 
       DoEvents
    Loop
    End Sub调用的时候这样写:
    ...
    Delay 1000  '延时一秒
    ...用这个过程比较好,不会造成程序“假死”的现象。
      

  16.   

    Public Sub Delay(DelayTime As Single)
        Dim BeginTime As Single
        BeginTime = Timer
        While Timer < BeginTime + DelayTime
            DoEvents
        Wend
    End Subdelay 1.5