完整代码如下,可以解释。
Private f As Integer, m As Integer
Private Sub Command1_Click()
Dim n As Integer
Do
n = Val(InputBox("请输入秒数:(小于3600)"))
Loop Until (n < 3600)
f = n \ 60: m = n Mod 60
Label1.Caption = f & ":" & m
End Sub
Private Sub Command2_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
m = m - 1
If m = 0 Then
If f > 0 Then
f = f - 1: m = 60
Else
Timer1.Enabled = False
Label1.Caption = "时间到!"
Exit Sub
End If
End If
Label1.Caption = f & ":" & m
End Sub
效果图:请验证!符合要求就请上分。
思路如下:
将设置值存为一个全局变量x
放置一个Timer,设置Interval为1000
在Timer1_Timer()中
对x减一操作
判断x=0时
label1.visible=true
需要的话可以给你定时关机的代码