这是一个简单的计时器
Private Sub CommandButton1_Click()
Dim Duration, Start As Long
Duration = TextBox2.Text
Start = Timer
Do While Timer < Start + Duration
DoEvents
TextBox1.Text = Duration - (Timer - Start)
Loop
TextBox1.Text = 0
MsgBox "OK", vbOKOnly, "Title"
End Sub
下面的是一个辩论用的计时器
Dim Selected As Long
Private Sub CommandButton1_Click()
Selected = 1
End Sub
Private Sub CommandButton2_Click()
Selected = 2
End Sub
Private Sub CommandButton3_Click()
Dim Duration1, Start1, End1, Duration2, Start2, End2 As Long
Duration1 = TextBox1.Text
Duration2 = TextBox2.Text
Selected = 1
Start = Timer
Do While Duration1 + Duration2 >= 0
If Selected = 1 Then
Do While Duration1 > 0
Start1 = Timer
If Selected = 1 Then
DoEvents
Duration1 = Duration1 - (Timer - Start1)
TextBox1.Text = Duration1
If Duration1 <= 0 Then
MsgBox "正方时间到", vbOKOnly, "Title"
Selected = 2
Exit Do
End If
Else
Exit Do
End If
Loop
ElseIf Selected = 2 Then
Do While Duration2 > 0
Start2 = Timer
If Selected = 2 Then
DoEvents
Duration2 = Duration2 - (Timer - Start2)
TextBox2.Text = Duration2
If Duration2 <= 0 Then
MsgBox "反方时间到", vbOKOnly, "Title"
Selected = 1
Exit Do
End If
Else
Exit Do
End If
Loop
End If
Loop
TextBox1.Text = 0
MsgBox "OK", vbOKOnly, "Title"
End Sub