
VB倒计时器 点开始就开始,结束时弹出“时间到”消息框 点击取消弹出“是否取消”息框! 15
标签上能显示开始时间:00:00:00结束时间:00:00:00共用了00:00:00共三个标签,点击开始计时时标签上的时间开始计时,点击停止计时时就停止,同时第三个标签...
标签上能显示
开始时间:00:00:00
结束时间:00:00:00
共用了00:00:00
共三个标签,点击开始计时时标签上的时间开始计时,点击停止计时时就停止,同时第三个标签显示总用时! 展开
开始时间:00:00:00
结束时间:00:00:00
共用了00:00:00
共三个标签,点击开始计时时标签上的时间开始计时,点击停止计时时就停止,同时第三个标签显示总用时! 展开
2个回答
展开全部
放一个command1按钮,做按键。
放两个text1和text2控件,1用来填分钟数(M),2用来填秒数(S)
放一个timer1定时器,设interval=1000。
*---设置按键功能和TEXT控件检测----*
dim M as integer
dim S as integer
public sub Command1_Click()
if command1.caption="继续" then
command1.caption="停止"
*---分钟和秒钟初始设置----*
M=val(text1.text)
S=val(text2.text)
if M<0 then
msgbox "分钟数应该为正"
text1.setfocuse
exit sub
end if
if S<0 or S>60 then
msgbox "秒数应该为正"
text2.setfocuse
exit sub
end if
timer1.enabled=true
else
command1.caption="继续"
timer1.enabled=false
endif
end sub
*---时钟控件 S60到0循环直到M=0,S=0表示时间到----*
private sub Timer1_timer()
s=s-1
if s<=0 and m>0 then
s=60
m=m-1
exit sub
end if
if M<=0 and S<=0 then
msgbox "时间到"
command1_Click
end if
end sub
放两个text1和text2控件,1用来填分钟数(M),2用来填秒数(S)
放一个timer1定时器,设interval=1000。
*---设置按键功能和TEXT控件检测----*
dim M as integer
dim S as integer
public sub Command1_Click()
if command1.caption="继续" then
command1.caption="停止"
*---分钟和秒钟初始设置----*
M=val(text1.text)
S=val(text2.text)
if M<0 then
msgbox "分钟数应该为正"
text1.setfocuse
exit sub
end if
if S<0 or S>60 then
msgbox "秒数应该为正"
text2.setfocuse
exit sub
end if
timer1.enabled=true
else
command1.caption="继续"
timer1.enabled=false
endif
end sub
*---时钟控件 S60到0循环直到M=0,S=0表示时间到----*
private sub Timer1_timer()
s=s-1
if s<=0 and m>0 then
s=60
m=m-1
exit sub
end if
if M<=0 and S<=0 then
msgbox "时间到"
command1_Click
end if
end sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Public a
Public b
Private Sub Form_Load()
Timer1.Enabled = False
Command1.Caption = "开始"
Command2.Caption = "暂停"
End Sub
Private Sub Timer1_Timer()
b = b + 1
If b > 59 Then
a = a + 1
b = 0
End If
Label2 = "结束时间为" & Val(Text1.Text) & "分" & Val(Text2.Text) & "秒"
If Val(Text2.Text) <= 0 Then
Text2.Text = 59
Text1.Text = Text1.Text - 1
Else
Text2.Text = Text2.Text - 1
End If
If Val(Text1.Text) = 0 And Val(Text2.Text) = 0 Then
MsgBox "时间到"
Timer1.Enabled = False
Label3 = "所用的时间为" & a & "分" & b & "秒"
End If
End Sub
Private Sub Command1_Click()
a = 0
b = 0
If Val(Text1.Text) = 0 And Val(Text2.Text) = 0 Then
Label1 = "没有输入时间,计时没有执行"
Timer1.Enabled = False
Command1.Caption = "输入时间开始计时"
Label2 = "(∩_∩) ? ! "
Label2.ForeColor = vbBlue
Else
Timer1.Enabled = True
Timer1.Interval = 1000
Label1 = "开始时间为" & Val(Text1.Text) & "分" & Val(Text2.Text) & "秒"
End If
Private Sub Command2_Click()
Timer1.Enabled = False
Label3 = "所用的时间为" & a & "分" & b & "秒"
End Sub
Public b
Private Sub Form_Load()
Timer1.Enabled = False
Command1.Caption = "开始"
Command2.Caption = "暂停"
End Sub
Private Sub Timer1_Timer()
b = b + 1
If b > 59 Then
a = a + 1
b = 0
End If
Label2 = "结束时间为" & Val(Text1.Text) & "分" & Val(Text2.Text) & "秒"
If Val(Text2.Text) <= 0 Then
Text2.Text = 59
Text1.Text = Text1.Text - 1
Else
Text2.Text = Text2.Text - 1
End If
If Val(Text1.Text) = 0 And Val(Text2.Text) = 0 Then
MsgBox "时间到"
Timer1.Enabled = False
Label3 = "所用的时间为" & a & "分" & b & "秒"
End If
End Sub
Private Sub Command1_Click()
a = 0
b = 0
If Val(Text1.Text) = 0 And Val(Text2.Text) = 0 Then
Label1 = "没有输入时间,计时没有执行"
Timer1.Enabled = False
Command1.Caption = "输入时间开始计时"
Label2 = "(∩_∩) ? ! "
Label2.ForeColor = vbBlue
Else
Timer1.Enabled = True
Timer1.Interval = 1000
Label1 = "开始时间为" & Val(Text1.Text) & "分" & Val(Text2.Text) & "秒"
End If
Private Sub Command2_Click()
Timer1.Enabled = False
Label3 = "所用的时间为" & a & "分" & b & "秒"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询