VB做倒计时

来源:百度知道 编辑:UC知道 时间:2024/06/24 23:01:50
定义函数分和秒分别为M,S
在TEXT1和TEXT2中输入数字分别对应M,S,摁下开始键后进行倒计时,摁下停止键后,倒计时停止,摁下开始键后,从停止时间再次运行,
时间显示在FRAME中,M不许为负数,0<s<60,可以用TIME控件,

简单!初学的吧?记着给分!

放两个text1和text2控件,分别输入数字对应分,秒。
放一个command1按钮
放一个timer1定时器,设interval=1000,enalbed=false

代码:
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

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 "时间到"