Code optimization on minutes pr hour calculation

Posted by corger on Stack Overflow See other posts from Stack Overflow or by corger
Published on 2010-05-25T08:19:29Z Indexed on 2010/05/25 8:21 UTC
Read the original article Hit count: 319

Hi All,

The following code takes a timeframe in minutes since midnight and creates an array with minutes pr hour. But, it's slow. Any better suggestions out there? (no, changing language is not an option :-) )

Const clDeparture   As Long = 123
Const clArrival     As Long = 233
Dim lHour           As Long
Dim lMinute         As Long
Dim alHour(25)      As Long

For lMinute = 0 To 1440
    If lMinute >= clDeparture And lMinute < clArrival Then
        alHour(Int(lMinute / 60)) = alHour(Int(lMinute / 60)) + 1
    End If
Next

The array should now contain:

(0,0) (1,0) (2,57) (3,53) (4,0) .....

Regards

© Stack Overflow or respective owner

Related posts about optimization

Related posts about vb