I have a little function that converts seconds into other units. Let's take a look at it.


Function FormatTime(TimeElapsed As Integer) As String
Dim Seconds As Integer
Dim Minutes As Integer
Dim Hours As Integer

'Find The Seconds
Seconds = TimeElapsed Mod 60

'Find The Minutes
Minutes = (TimeElapsed \ 60) Mod 60

'Find The Hours
Hours = (TimeElapsed \ 3600)

'Format The Time
If Hours > 0 Then
FormatTime = Format(Hours,"00") & ":"
End If
FormatTime = Format(Hours, "00") & ":"
FormatTime = FormatTime & Format(Minutes, "00") & ":"
FormatTime = FormatTime & Format(Seconds, "00")
End Function

Let's take a closer look at this. First, I used the Mod operationto get the seconds. "Mod" finds the remainder when one number is divided byanother. In this case, when we divide our time elapsed by 60 (one minute), ourremainder is the number of seconds left over.

Then I did a similar process to find the minutes, only this time I had to divide the numberof seconds by 60 to get the total number of minutes. Again, I used the Modoperator to find the remainder (in this case, the number of leftover minutes).

Finally, the number of hours is the number of seconds divided by 3600. Once again, I usedInteger division ('\' instead of '/') because we don't want fractional hours.

The last step of the process is putting the values together in a string, using the Formatfunction to get the right number of digits in each section.