VB计时器代码
我在窗体里弄了设置倒计时时间的Text1.2.3
然后是开始.结束的Command1.2
之后是显示剩余秒数的Label1
最后一个Timer1
但是我听说,用Timer好像会出现时间偏差,能不能用其他组件代替Timer,但是务必保持其他组件不变,谢谢!
如果没有问题,就给分
至于分数大小吗~~你就先别猜
1楼好无聊哦~
代码好了,但是能不能在时间结束后,发出我设置的提示提示音?(我用的2楼的代码)
timer的最郑指小精度是55毫秒,但是如果设置为1毫秒,或者 56毫喊雀配秒。都是110毫秒的精度.
但是精确到 150,250毫秒是没有问题的.
无法精确到1个毫秒的.或者百分之一岁态秒.
现在有高精度的timer控件,但是是第三方控件,需要付费使用的.
Dim t As Integer
Private Sub Command1_Click()
Timer1.Interval = 1000
Timer1.Enabled = True
t = Val(Text1.Text)
Label1.Caption = Str(t)
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
Label1.Caption = ""
End Sub
Private Sub Timer1_Timer()
t = t - 1
If t = 0 Then
MsgBox "时间到!!"
Timer1.Enabled = False
end if
Label1.Caption = Str(t)
End Sub
Dim
a
As
Integer
Private
Sub
Command1_Click()
If
Command1.Caption
=
"开始计时升并"
Then
Timer1.Enabled
=
True
Command1.Caption
=
"暂停"
Else
Command1.Caption
=
"开始计时"
Timer1.Enabled
=
False
End
If
End
Sub
Private
Sub
Command2_Click()
Timer1.Enabled
=
False
a
=
0
Label1.Caption
=
0
Command1.Caption
=
"开始计时"
End
Sub
Private
Sub
Form_Load()
Command1.Caption
=
"开始念禅计时"
Timer1.Enabled
=
False
Command2.Caption
=
"结束计时"
End
Sub
Private
Sub
Timer1_Timer()
Label1.Caption
=
a
a
=
a
+
1
End
Sub
刚写了下,有点粗糙
两个command控件,一个timer,一个label
具体吵高迹功能看代码
如有问题,请追问
使用timer控件,芦脊埋把属性interval设置为1000
然后再timer_timer事件中添加加1方法即可野贺。陪蚂
如图
代码如下:
Public
FTime
As
Integer
Private
Sub
Command1_Click()
Me.Timer1.Enabled
=
True
End
Sub
Private
Sub
Command2_Click()
Me.Timer1.Enabled
=
False
End
Sub
Private
Sub
Form_Load()
Me.Timer1.Enabled
=
False
Me.Timer1.Interval
=
1000
End
Sub
Private
Sub
Timer1_Timer()
FTime
=
FTime
+
1
Me.Label1.Caption
=
"计时(秒):"
&
FTime
End
Sub
设置计时器蔽察的.Interval
属性后坦并卜,加上这样一段代码就让穗可以了
Private
Sub
Command2_Click()
Timer1.Enabled
=
true
End
Sub
‘与楼上桐斗效果一样
Private
Sub
Command1_Click()
Timer1.Enabled
=
True
Timer1.Interval
=
1000
End
Sub
Private
Sub
Timer1_Timer()
Static
a
As
Long
Me.Cls
Me.FontSize
=
20
Me.ForeColor
=
&HFF&
Me.CurrentX
=
1000
Me.CurrentY
=
1000
a
=
a
+
1
Print
"计盯亮时:凯轮宽
"
&
Format(a,
"00")
End
Sub