帮我把这个代码解释写出来。在线等。谢谢。
1、在窗体上添加一个label1控件
2、在窗体上添加一个command1控件
3、在窗体上添加一个timer1控件
4、复制如下代码,运行
Dim a As Long
Private Sub Command1_Click()
a = InputBox("请输入秒数")
Label1.Caption = a
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = False
Command1.Caption = "记时开始"
End Sub
Private Sub Timer1_Timer()
a = a - 1
Label1.Caption = a
Print a
If a = 0 Then
Timer1.Enabled = False
End If
End Sub
求vb倒时计时器代码解释
答案:2 悬赏:70 手机版
解决时间 2021-03-24 10:21
- 提问者网友:浮克旳回音
- 2021-03-23 22:36
最佳答案
- 五星知识达人网友:人间朝暮
- 2021-03-23 23:03
Dim a As Long
Private Sub Command1_Click() //触发click事件
a = InputBox("请输入秒数") //输入倒计时秒数
Label1.Caption = a //显示a
Timer1.Enabled = True //启动计时器
End Sub
Private Sub Form_Load() //先执行
Timer1.Interval = 1000 //初始化,时间间隔1秒
Timer1.Enabled = False //计时器禁用
Command1.Caption = "记时开始" //让按钮显示“计时开始”
End Sub
Private Sub Timer1_Timer() //每隔一秒执行一次
a = a - 1 //计数器
Label1.Caption = a //显示剩余秒数
Print a //显示a
If a = 0 Then //控制循环,到a变为零即计时结束
Timer1.Enabled = False
End If
End Sub
Private Sub Command1_Click() //触发click事件
a = InputBox("请输入秒数") //输入倒计时秒数
Label1.Caption = a //显示a
Timer1.Enabled = True //启动计时器
End Sub
Private Sub Form_Load() //先执行
Timer1.Interval = 1000 //初始化,时间间隔1秒
Timer1.Enabled = False //计时器禁用
Command1.Caption = "记时开始" //让按钮显示“计时开始”
End Sub
Private Sub Timer1_Timer() //每隔一秒执行一次
a = a - 1 //计数器
Label1.Caption = a //显示剩余秒数
Print a //显示a
If a = 0 Then //控制循环,到a变为零即计时结束
Timer1.Enabled = False
End If
End Sub
全部回答
- 1楼网友:长青诗
- 2021-03-24 00:07
昨天在网吧写的代码没有了,我郁闷啊.
今天把界面丰富了一下,你看看吧,不知道你说的启用键盘回车功能干什么,所以没有涉及到.仍然要感谢rainbow_route.窗体中一个textbox,三个command,一个timmer,看不到字就把textbox弄大点.
private declare function gettickcount lib "kernel32" () as long
public tstart, tnow, tlast, tminute, tsecond, ttotal
private sub command1_click()
command1.enabled = false: command2.enabled = true: command4.enabled = false
text1.text = ""
end sub
private sub command2_click()
command3.enabled = true
timer1.enabled = true
ttotal = tlast + ttotal
tstart = gettickcount
call timer1_timer
end sub
private sub command3_click()
command1.enabled = true: command2.enabled = false
command3.enabled = false: command4.enabled = true
timer1.enabled = false
tstart = 0: tend = 0: ltime = 0: tminute = 0: tsecond = 0: tlast = 0
end sub
private sub command4_click()
end
end sub
private sub form_load()
command1.caption = "开始": command2.caption = "计时": command3.caption = "停止": command4.caption = "退出"
command1.default = true: command2.enabled = false: command3.enabled = false
timer1.interval = 1000: timer1.enabled = false
tstart = 0: tend = 0: ltime = 0: tminute = 0: tsecond = 0: tlast = 0
end sub
private sub timer1_timer()
tnow = gettickcount
tlast = val(tnow - tstart) \ 1000
tminute = tlast \ 60
tsecond = tlast mod 60
text1.text = "距你本次点击[计时]的时间为" & tminute & ":" & tsecond & vbcrlf & "从第一次点击[计时]到本次点击经过了:" & ttotal & "秒"
end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯