用VB编写倒计时程序的问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 16:59:40
希望达到这样的效果:有3个文本框,分别是时、分、秒

还有一个按钮

用户输入了时间,之后点按钮,就会启动倒计时。

比如输入的是倒计时29小时08分35秒。点击按钮启动倒计时。这样就能看到文本框的数字变成了29 08 34 29 08 33 29 08 32……
时间到了用一个消息框提示用户。

请各位指点一下。
回答得满意就加分

在窗体添加三个 text 一个timer 一个command
text1 text2 text3 分别代表 hh mm ss
timer1 是定时器,计时用的
command1 是开始计时按钮

然后在窗体代码内粘贴以下全部代码,运行即可

Option Explicit
Public hh As Long, mm As Long, ss As Long

Private Sub Command1_Click()
hh = Val(Text1.Text)
mm = Val(Text2.Text)
ss = Val(Text3.Text)
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Sub Form_Load()
Text1.Text = "16"
Text2.Text = "00"
Text3.Text = "05"
Timer1.Enabled = False

End Sub

Private Sub Timer1_Timer()
ss = ss - 1
If ss < 0 Then
mm = mm - 1
If mm < 0 Then
hh = hh - 1
If hh < 0 Then
Text1.Text = "00"
Text2.Text = "00"
Text3.Text = "00"
MsgBox "时间到了!"
Timer1.Enabled = False