Public duan As Boolean '断点Public Function Sleep2(T As Long)
    Dim Savetime As Long
    Dim ttttt As Boolean
      Savetime = timeGetTime '记下开始时的时间
    Do While timeGetTime < Savetime + T '循环等待
    ttttt = duan
    If ttttt = False Then Exit Function
    If ttttt = False Then Label6.Caption = "已退sleep2"
        DoEvents '转让控制权
    Loop
End Function

解决方案 »

  1.   

    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Const iSeparator      As Long = 50     '每200毫秒检查一次用户是否下令中断;
    Private Sub CommandButton1_Click()
        callSleep
    End SubPrivate Sub callSleep()
        Dim beginTime   As Long
        Dim theTime     As Long
        
        beginTime = GetTickCount()
        
        Do While True
            theTime = GetTickCount()
            If beginTime + iSeparator < theTime Then
                If CheckBox1.Value = True Then
                    Exit Sub
                End If
                beginTime = theTime
                Label1.Caption = Str(theTime)
                Sleep iSeparator
            End If
            DoEvents
        Loop
    End Sub
    不好意思,时间关系,没能测试一下
      

  2.   

    您好,感谢,
    callSleep可以带参数么?我需要停止一个指定的时间,再继续执行下面的语句