在窗体中放入一个TextBox ,一个 Label,一个Timer控件.
TextBox 用于输入定时的最终时间,要用这格式:"00:01:25" ;
Label 用于显示定时时钟运行的时间;
Command 开始和关闭定时时钟.
Private Sub Form_Load()
Timer1.Interval = 1000
End Sub
Private Sub Command1_Click()
If Command1.Caption = "开 始 计 时" Then
Text1.Enabled = False
Timer1.Enabled = True
Command1.Caption = "停 止 计 时"
Else
Timer1.Enabled = False
Text1.Enabled = True
Command1.Caption = "开 始 计 时"
End If
End Sub
Private Sub Timer1_Timer()
总时间 = 总时间 + 1
Label1.Caption = Format(总时间, "00:00:00")
If Trim(Label1.Caption) = Trim(Text1.Text) Then
Call Command1_Click
Beep
MsgBox "时间到!"
End If
End Sub
简单:就是不知道你的定时目的是什么,可以用以下代码实现,加载一个COMMAND1,TIMER1,两个TEXTBOX,三个LABEL:
Dim n As Integer, time0
Private Sub Command1_Click()
time0 = 3600 * Val(Text1.Text) + 60 * Val(Text2.Text)
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Label3.FontSize = 30
End Sub
Private Sub Timer1_Timer()
n = n + 1
n1 = time0 - n
h = n1 \ 3600
m = n1 \ 60 - h * 60
s = n1 - h * 3600 - m * 60
Label3.Caption = "倒计时:" & h & "小时" & m & "分" & s & "秒"
If n1 = 0 Then
Label3.Caption = "时间到"
Timer1.Enabled = False
End If
End Sub