补充等待功能

发表于:2007-06-21来源:作者:点击数: 标签:
Implementing a "wait" function in VB Here注释:s a simple way of implementing an accurate "wait" function in VB. Add a timer called timer1 to a form. Set its Interval property to 0 and it注释:s enabled property to FALSE. Add two labels (l

   
  Implementing a "wait" function in VB

Here注释:s a simple way of implementing an aclearcase/" target="_blank" >ccurate "wait" function in VB.

Add a timer called timer1 to a form. Set its Interval property to 0 and it注释:s enabled property to FALSE.

Add two labels (label1 and label2) and a command button (command1) to the form.
Add the following subroutine and Timer1 event code:

Public Sub Wait(seconds)

    注释:-- Turn timer on
    Timer1.Enabled = True

    注释:-- Set Timer Interval
    Me.Timer1.Interval = 1000 * seconds
    While Me.Timer1.Interval > 0
        DoEvents
    Wend

    注释:-- Turn timer off
    Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
    Timer1.Interval = 0
End Sub

That注释:s it! Use the Wait function anywhere a delay is required, for example:

Private Sub Command1_Click()
    Label1.Caption = Now
    Wait (5)
    Label2.Caption = Now
End Sub

原文转自:http://www.ltesting.net