hi this my code
[code=vb]
Private Sub Form_Load()
car_count = 0
Cumulative_Spee d = 0
End Sub
Private Sub Timer1_Timer()
Dim tmpNumber As Integer
Dim i As Integer
Dim Counter As Integer
Timer1.Enabled = False 'stop timing while storing number
Counter = 0
Randomize
lbltmpNumber = Int(Rnd() * 15) + 1
'check if this number already exist
For i = 0 To 9
If lblCar(i) = lbltmpNumber And lblEnd(i) = "" Then
'the number exist -> do not store it
EndTime = Now
lblEnd(i).Capti on = Format(EndTime, "hh:mm:ss")
StartTime = lblTime(i)
Timeduration = (((DatePart("h" , EndTime) - DatePart("h", StartTime)) * 3600) + ((DatePart("n", EndTime) - DatePart("n", StartTime)) * 60) + (DatePart("s", EndTime)) - DatePart("s", StartTime))
lblDuration(i). Caption = "" & Timeduration
' Count number of car which succesfully pass through reader 2
car_count = car_count + 1
lblNum.Caption = car_count
' Call a function to calculate speed
S = Speed()
lblSpeed(i).Cap tion = S
lblSpeed(i).Cap tion = Format(S, "###.00")
' Calculate the Average Speed
Cumulative_Spee d = Cumulative_Spee d + S
lblAverage.Capt ion = Format(Cumulati ve_Speed / car_count, "###.00")
Timer1.Enabled = True
Exit For
ElseIf lblCar(i) = lbltmpNumber Then
Timer1.Enabled = True
Exit For
End If
Next
'If this number does not exist -> store in Number Array
If Timer1.Enabled = False Then
lblCar(Index).C aption = lbltmpNumber 'store the number
StartTime = Now
lblTime(Index). Caption = Format(StartTim e, "hh:mm:ss") 'store the time
Index = Index + 1
End If
If Index = 10 Then 'stop after stored 10 number
Timer1.Enabled = False
Else 'do not reach 10
Timer1.Enabled = True 'continue storing
End If
End Sub
Private Function Speed()
Speed = (100 / Timeduration) * (1000 / 3600)
End Function
[/code]
My question here is how i modify my code to take total average speed for every 5 min.that means how to make car array reset and store the average then again display random number until 10 then store average n again an again until it 5 min. in 5 min all this array need to be sum and display the total average .
[code=vb]
Private Sub Form_Load()
car_count = 0
Cumulative_Spee d = 0
End Sub
Private Sub Timer1_Timer()
Dim tmpNumber As Integer
Dim i As Integer
Dim Counter As Integer
Timer1.Enabled = False 'stop timing while storing number
Counter = 0
Randomize
lbltmpNumber = Int(Rnd() * 15) + 1
'check if this number already exist
For i = 0 To 9
If lblCar(i) = lbltmpNumber And lblEnd(i) = "" Then
'the number exist -> do not store it
EndTime = Now
lblEnd(i).Capti on = Format(EndTime, "hh:mm:ss")
StartTime = lblTime(i)
Timeduration = (((DatePart("h" , EndTime) - DatePart("h", StartTime)) * 3600) + ((DatePart("n", EndTime) - DatePart("n", StartTime)) * 60) + (DatePart("s", EndTime)) - DatePart("s", StartTime))
lblDuration(i). Caption = "" & Timeduration
' Count number of car which succesfully pass through reader 2
car_count = car_count + 1
lblNum.Caption = car_count
' Call a function to calculate speed
S = Speed()
lblSpeed(i).Cap tion = S
lblSpeed(i).Cap tion = Format(S, "###.00")
' Calculate the Average Speed
Cumulative_Spee d = Cumulative_Spee d + S
lblAverage.Capt ion = Format(Cumulati ve_Speed / car_count, "###.00")
Timer1.Enabled = True
Exit For
ElseIf lblCar(i) = lbltmpNumber Then
Timer1.Enabled = True
Exit For
End If
Next
'If this number does not exist -> store in Number Array
If Timer1.Enabled = False Then
lblCar(Index).C aption = lbltmpNumber 'store the number
StartTime = Now
lblTime(Index). Caption = Format(StartTim e, "hh:mm:ss") 'store the time
Index = Index + 1
End If
If Index = 10 Then 'stop after stored 10 number
Timer1.Enabled = False
Else 'do not reach 10
Timer1.Enabled = True 'continue storing
End If
End Sub
Private Function Speed()
Speed = (100 / Timeduration) * (1000 / 3600)
End Function
[/code]
My question here is how i modify my code to take total average speed for every 5 min.that means how to make car array reset and store the average then again display random number until 10 then store average n again an again until it 5 min. in 5 min all this array need to be sum and display the total average .