VB写的倒计时程序没有显示出倒计时的过程
一个VB写的倒计时程序,但是没有显示出倒计时的过程,恳请高手给看看问题在哪?该怎样改?谢谢
窗体控件如下:
三个TextBox控件,分别是Text1用于记录小时,Text2用于记录分钟,Text3用于记录秒。一个Label控件,Label1,用于显示时间。还有三个Button控件,Command1,Command2和Command3,分别实现开始计时,暂停计时和重新计时功能。还有一个Timer控件,Timer1
代码如下:
'窗体全局变量
Dim Hours As Integer '记录小时
Dim Minutes As Integer '记录分钟
Dim Seconds As Integer '记录秒
Dim Time As Date
Private Sub Mydisplay()
Hours = Val(Text1.Text)
Minutes = Val(Text2.Text)
Seconds = Val(Text3.Text)
Time = TimeSerial(Hours, Minutes, Seconds) '组合字符串
'将字符串转化为时间格式
Label1.Caption = Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
Command1.Enabled = False
Command2.Enabled = True
Command3.Enabled = True
End Sub
Private Sub Command2_Click()
If Timer1.Enabled Then
Timer1.Enabled = False
End If
Hours = 0
Minutes = 0
Seconds = 0
Time = 0
Command1.Enabled = True
Command3.Enabled = False
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text1.SetFocus '将焦点放到Text1控件上
End Sub
Private Sub Command3_Click()
Timer1.Enabled = False
Command3.Enabled = False
Command1.Enabled = True
Command2.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000 '将Timer控件的事件引发间隔设置成1000毫秒
'初始化变量
Hours = 0
Minutes = 0
Seconds = 0
Time = 0
End Sub
Private Sub Text1_Change() 'TextBox控件事件,当控件的Text值改变时引发该事件
Mydisplay
End Sub
Private Sub Text2_Change()
Mydisplay
End Sub
Private Sub Text3_Change()
Mydisplay
End Sub
Private Sub Timer1_Timer() 'Timer控件的事件
Timer1.Enabled = False
If (Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")) <> "00:00:00" Then 'Counter to continue loop until 0
Time = DateAdd("s", -1, Time)
Label1.Caption = Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")
Timer1.Enabled = True
Else
'如果未输入时间或时间为零则发出警报
Timer1.Enabled = False
Beep
Beep
Command2.Enabled = True
End If
End Sub
搜索更多相关主题的帖子:
倒计时 程序 出倒