By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,366 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,366 IT Pros & Developers. It's quick & easy.

STORE average speed for every 5 min

P: 27
hi this my code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. car_count = 0
  3. Cumulative_Speed = 0
  4. End Sub
  5.  
  6.       Private Sub Timer1_Timer()
  7.  
  8.       Dim tmpNumber As Integer
  9.  
  10.       Dim i As Integer
  11.       Dim Counter As Integer
  12.       Timer1.Enabled = False    'stop timing while storing number
  13.       Counter = 0
  14.  
  15.       Randomize
  16.  
  17.       lbltmpNumber = Int(Rnd() * 15) + 1
  18.  
  19.       'check if this number already exist
  20.  
  21. For i = 0 To 9
  22.  
  23.         If lblCar(i) = lbltmpNumber And lblEnd(i) = "" Then
  24.  
  25.             'the number exist -> do not store it
  26.             EndTime = Now
  27.             lblEnd(i).Caption = Format(EndTime, "hh:mm:ss")
  28.             StartTime = lblTime(i)
  29.             Timeduration = (((DatePart("h", EndTime) - DatePart("h", StartTime)) * 3600) + ((DatePart("n", EndTime) - DatePart("n", StartTime)) * 60) + (DatePart("s", EndTime)) - DatePart("s", StartTime))
  30.             lblDuration(i).Caption = "" & Timeduration
  31.  
  32.             ' Count number of car which succesfully pass through reader 2
  33.  
  34.             car_count = car_count + 1
  35.             lblNum.Caption = car_count
  36.  
  37.             ' Call a function to calculate speed
  38.  
  39.             S = Speed()
  40.             lblSpeed(i).Caption = S
  41.             lblSpeed(i).Caption = Format(S, "###.00")
  42.  
  43.             ' Calculate the Average Speed
  44.  
  45.             Cumulative_Speed = Cumulative_Speed + S
  46.  
  47.             lblAverage.Caption = Format(Cumulative_Speed / car_count, "###.00")
  48.  
  49.             Timer1.Enabled = True
  50.  
  51. Exit For
  52.             ElseIf lblCar(i) = lbltmpNumber Then
  53.  
  54.             Timer1.Enabled = True
  55.  
  56. Exit For
  57.           End If
  58. Next
  59.  
  60.       'If this number does not exist -> store in Number Array
  61.  
  62.       If Timer1.Enabled = False Then
  63.       lblCar(Index).Caption = lbltmpNumber  'store the number
  64.       StartTime = Now
  65.       lblTime(Index).Caption = Format(StartTime, "hh:mm:ss")  'store the time
  66.       Index = Index + 1
  67.  
  68.  
  69.        End If
  70.  
  71.       If Index = 10 Then   'stop after stored 10 number
  72.  
  73.        Timer1.Enabled = False
  74.  
  75.  
  76.       Else  'do not reach 10
  77.       Timer1.Enabled = True    'continue storing
  78.  
  79.       End If
  80.  
  81.       End Sub
  82.  
  83.  
  84. Private Function Speed()
  85.  
  86. Speed = (100 / Timeduration) * (1000 / 3600)
  87. End Function
  88.  
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 .
Mar 26 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.