VB计时器代码

来源:百度知道 编辑:UC知道 时间:2024/06/24 07:16:57
我在窗体里弄了设置倒计时时间的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

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 = ""