Dim a As String
Dim s As Integer
Private Sub Command1_Click()
a = InputBox("输入格式为:" & vbCrLf & " 时,分,妙 ", "输入倒计时", "0,0,60")
x = Split(a, ",")
For i = 0 To UBound(x)
Print x(i)
Next i
s = Val(x(0)) * 60 * 60 + Val(x(1)) * 60 + Val(x(2))
End Sub
Private Sub Command2_Click()
If Command2.Caption = "开始" Then
Command2.Caption = "暂停"
Timer1.Enabled = True
Else
Timer1.Enabled = False
Command2.Caption = "开始"
End If
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000
Command2.Caption = "开始"
End Sub
Private Sub Timer1_Timer()
s = s - 1
Label1.Caption = "剩余" & s \ 3600 & ":" & (s \ 60) Mod 60 & ":" & s Mod 60
If s <= 0 Then
MsgBox "时间到了,赶快去做该做的事!o(∩_∩)o 哈哈"
End If
End Sub
'日曜星君原创作品
'添加一个label,一个commandbutton,一个textbox,不要改名
Dim mTime As Double
Private Sub Form_Load()
Text1.Text = 120
'初始化默认倒计时时间为120秒
Timer1.Interval = 100
'Timer的执行周期,这个不要改
End Sub
Private Sub Command1_Click()
mTime = Text1.Text
'设置倒计时时间
Timer1.Enabled = True
'开始倒计时
End Sub
Private Sub Timer1_Timer()
i = i + 1
'增加已经过去的毫秒数
mTime = mTime - i / 10
'总数减去已经过去的毫秒数,就是剩余时间
Label1.Caption = Format(mTime, "0.0")
'在label1中显示出来!
End Sub
'日曜星君原创作品
参考资料: http://quwen168.com