我再commandbottom 的 click事件中 要发生 2个事件  但是我想要这两个
事件 间隔 1 秒 ,我有哪些方法可以实现呢? 谢谢1 再现等候~:)

解决方案 »

  1.   

    Dim ys As Single
    ys = Timer + 1
    Do
        DoEvents
    Loop Until Timer > ys
      

  2.   

    timer 控件
    在command_click 中使timer enabled,
    在timer 中执行第二个事件.
    sleep()会使整个程序停止响应.
      

  3.   

    Private Sub Command1_Click()
     Print "t1"
     Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Timer()
      Print "t2"
      Timer1.Enabled = False
    End Sub
      

  4.   

    用timer 控件
    来控制,不过这段时间它占用cpu
      

  5.   

    用Timer好麻烦
    用wait函数
    具体请看msdn中文版
      

  6.   

    Static Sub LastSub(LastTime)
    Dim loopfinisH
    Const SecondsInday = 24& * 60& * 60
    loopfinisH = Timer + LastTime
    If loopfinisH > SecondsInday Then
        loopfinisH = loopfinisH - SecondsInday
        Do While Timer > loopfinisH
        DoEvents
        Loop
    End If
    Do While Timer < loopfinisH
    DoEvents
    Loop
    End Sub这是一个非常好用的延时函数,参数单位为秒。
    还有如果你程序此时不响应任何事件的话,还可以用
    Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
      

  7.   

    'This project needs a button
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Sub Command1_Click()    Me.Caption = "Your system will sleep 1 sec."    Sleep 1000
        Me.Caption = ""
    End Sub
    Private Sub Form_Load()
        Me.Caption = ""
        Command1.Caption = "Sleep ..."
    End Sub
      

  8.   

    Private Declare Function timeGetTime Lib "winmm.dll" () As Long 'Windows API函数,取得系统运行时间Function Waiting(PauseTime As Long) '等待时间
    Dim Start As Long
    Start = timeGetTime
    Do While (timeGetTime < Start + PauseTime)
      DoEvents
    Loop
    End Function单位:ms
      

  9.   

    sleep使用后回暂时把程序挂起,我感觉不好。
      

  10.   

    CreateWaitableTimer, SetWaitableTimer + MsgWaitForMultipleObjects比较麻烦,只是占用的 CPU 时间很少,并且可以响应事件。
    时间可以精确到 0.1 微秒(0.0001 毫秒)用在这里似乎有点杀鸡用牛刀,呵呵
      

  11.   

    可不可以这样子:
      
       dim i as Long    For i=0 to 10000
       
       Next i
      

  12.   

    先建一通用涵数
    ' Sleep (1000) ' Sleep for 1 seconds
    Sub Sleep(ByVal MillaSec As Long, Optional ByVal DeepSleep As Boolean = False)
        Dim tStart#, Tmr#
        tStart = Timer
        While Tmr < (MillaSec / 1000)
            Tmr = Timer - tStart
            If DeepSleep = False Then DoEvents
        Wend
    End Sub
    再在需要的地方
    call sleep(5000)'5000指延时5秒