timmer怎么用

来源:百度知道 编辑:UC知道 时间:2024/09/28 10:08:26
VB

你是不知道用它来做什么吧?看一下我随手写的例子:精确到1s的秒表
(我在网吧,没VB,故没调试,看大约思路及语法吧,有问题自已研究,包括语法的单词打错,OK?)

'添加一个Text控件:text1
'添加1个Timer控件:timer1
'添加2个Command控件:command1,command2

private sub Form_load()
command1.caption="归0并开始计时"
command2.caption="停止"
timer1.enabled=false '关闭Timer

timer1.interval=1000
'每1000毫秒(即1秒)执行一下Timer事件即Timer1_timer()过程
end sub
'-------------------------------------------------
private sub command1_click()'按钮1(计时)单击处理
text1.text="0"
timer1.enabled=true '激活timer1
end sub
'--------------------------------------------------
private sub command2_click()
timer1.enabled=false'关闭timer1
end sub
'--------------------------------------------------
private sub timer1_timer()
dim t as integer
t=val(text1.text)'text控件值(字符串)转为整型值
t=t+1
text1.text=str(t