延时函数

  • 来源: 互联网 作者: rocket   2008-03-18/09:31
  • 定义函数:
    Public Function Delay(Mins%, Secs%, Optional ByRef StopFlag) As Long
    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
    End Function
    使用例子:

    Dim StopTheTimer As Boolean

    Private Sub Command1_Click() '开始延时
    Dim lRetval&
    lRetval = Delay(1, 5, StopTheTimer)
    If lRetval = 0 Then
    MsgBox "时间到!"
    Else
    MsgBox "取消延时!"
    End If
    End Sub
    Private Sub Command2_Click() '取消延时
    StopTheTimer = True
    End Sub

    评论 {{userinfo.comments}}

    {{money}}

    {{question.question}}

    A {{question.A}}
    B {{question.B}}
    C {{question.C}}
    D {{question.D}}
    提交

    驱动号 更多