请问如何使一段程序延迟5秒后再继续运行!

解决方案 »

  1.   

    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 5 sec."
        'Sleep for 5000 milliseconds
        Sleep 5000
        Me.Caption = ""
    End Sub
    Private Sub Form_Load()
        Me.Caption = ""
        Command1.Caption = "Sleep ..."
    End Sub试试吧!^_^
      

  2.   

    本示例使用 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
      

  3.   

    Option Explicit
    Declare Function GetCurrentTime Lib "kernel32" Alias "GetTickCount" () As LongPublic Sub delay(ByVal intintel As Integer)’intintel 为秒数
        Dim lngOldtime As Long
        
        lngOldtime = GetCurrentTime / 1000 + intintel
        
        While lngOldtime > GetCurrentTime / 1000
            DoEvents
            
        
        WendEnd Sub