问题描述
请帮助我,我想知道是否有两个定时器(vb),它是并行还是同步。我在这里遇到问题,我想计算持续时间公式是EndTime-StartTime。我在第一个定时器中编码StartTime,在第二个定时器(Timer2)中编码EndTime,每个时间间隔为5s和10s。但是我面临的问题是,在公式正确的情况下,时间持续时间是不准确的。我为startTime n End Time创建了4个数组。 Plz指导我解决这个问题。
私有子Timer1_Timer()
随机化
lblCar(n) .Caption = Int(Rnd()* 50)
StartTime =现在
lblStart(n).Caption =格式(StartTime," hh:mm :ss")
n = n + 1
如果n = 4那么
Timer1.Enabled = False
结束如果
结束子
私人子Timer2_Timer()
EndTime =现在
lblEnd(i).Caption =格式(EndTime," hh:mm:ss")
Timeduration = DateDiff(" s" ,StartTime,EndTime)
lblDuration(i).Caption ="" &安培; Timeduration
i = i + 1
如果i = 4那么
Timer2.Enabled = False
结束如果
结束Sub
hi plz help me, i would like to know if got two timer in form( vb), does it run parallel or synchronous. i got problem here where i want to calculate time duration the formula is EndTime-StartTime. I code the StartTime in first timer and the EndTime in second Timer(Timer2) with 5s and 10s Interval each. BUT i facing problem here where the Time Duration is inaccurate eventhough the formula is correct. I created array of 4 for startTime n End Time. Plz guide me to solve this problem.
Private Sub Timer1_Timer()
Randomize
lblCar(n).Caption = Int(Rnd() * 50)
StartTime = Now
lblStart(n).Caption = Format(StartTime, "hh:mm:ss")
n = n + 1
If n = 4 Then
Timer1.Enabled = False
End If
End Sub
Private Sub Timer2_Timer()
EndTime = Now
lblEnd(i).Caption = Format(EndTime, "hh:mm:ss")
Timeduration = DateDiff("s", StartTime, EndTime)
lblDuration(i).Caption = "" & Timeduration
i = i + 1
If i = 4 Then
Timer2.Enabled = False
End If
End Sub
推荐答案
我认为你没有正确使用计时器。每次达到间隔时,计时器都会做你写的任何内容。
例如
如果你的计时器事件说:
I think you''re not using timers properly. Timers will do whatever you write in them every time the interval is reached.
e.g
if your timer event says:
这篇关于计时器的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!