Where are StartTime, EndTime and Timeduration declared? Um... samne goes for i and n, I suppose.
The actual code looks alright, I think. But of course I can't see what values you have, or what properties are set for the timer intervals, etc etc.
Can you give us a clearer idea of what seems to be wrong? "Inaccurate" is a pretty vague term.
Hi, thanks 4 d reply.sorry to msg u with unclear question. When the program runs the display 4 the time duration is wrong( wat i mean here is the output is wrong at the duration label even though the formula for time duration is correct). is it because i use two timer?. Timer1 i use 5000 interval and timer 2 i use 10000 interval. plz help me
My code:
Option Explicit
Dim StartTime As Variant
Dim EndTime As Variant
Dim n As Integer
Dim Timeduration As Variant
Dim duration As Variant
Dim i As Integer
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