Option ExplicitDim T As Long Private Sub Form_Load() T = 0 Timer1.Enabled = True Timer1.Interval = 60000 '一分钟触发一次 End SubPrivate Sub Timer1_Timer() T = T + 1 If T = 10 Then MsgBox "时间到", vbInformation End Sub
Dim Counter As IntegerPrivate Sub Command1_Click() If Command1.Caption = "计时开始" Then Command1.Caption = "计时结束" Counter = 0 Timer1.Enabled = True Else Command1.Caption = "计时结束" Timer1.Enabled = False End If End SubPrivate Sub Form_Load() Timer1.Interval = 60000 Timer1.Enabled = False Counter = 0 Command1.Caption = "计时开始" End SubPrivate Sub Timer1_Timer() Counter = Counter + 1 Print Counter If Counter Mod 10 = 0 Then Print "计时一次" End If End Sub
楼上的代码要改进一下:Private Sub Timer1_Timer() T = T + 1 If T = 10 Then MsgBox "时间到", vbInformation T=0 end if End Sub
Private Sub Form_Load()
T = 0
Timer1.Enabled = True
Timer1.Interval = 60000 '一分钟触发一次
End SubPrivate Sub Timer1_Timer()
T = T + 1
If T = 10 Then MsgBox "时间到", vbInformation
End Sub
If Command1.Caption = "计时开始" Then
Command1.Caption = "计时结束"
Counter = 0
Timer1.Enabled = True
Else
Command1.Caption = "计时结束"
Timer1.Enabled = False
End If
End SubPrivate Sub Form_Load()
Timer1.Interval = 60000
Timer1.Enabled = False
Counter = 0
Command1.Caption = "计时开始"
End SubPrivate Sub Timer1_Timer()
Counter = Counter + 1
Print Counter
If Counter Mod 10 = 0 Then
Print "计时一次"
End If
End Sub
T = T + 1
If T = 10 Then
MsgBox "时间到", vbInformation
T=0
end if
End Sub