WJM wrote:

I'm looking for some help with a error in the code below.

When 119.45 seconds are entered the code returns 01:59.45, but when you

enter 119.51 the code returns 02:59.51. But, if I enter 120.00 the code

returns 02:00.00. Can anyone help figure out what is happening?

Public Function Elasped_Time(TimeElapsed As Double) As String

Dim Tenths As Double

Dim Seconds As Double

Dim Minutes As Double

Dim Hours As Double

Dim A As String

'Find The Seconds

Seconds = Int(TimeElapsed) Mod 60

'Find The Minutes

Tenths = TimeElapsed - Int(TimeElapsed)

Minutes = (TimeElapsed \ 60) Mod 60

'Find The Hours

Hours = (TimeElapsed \ 3600)

'Format The Time

If Hours >= 0 Then

A = Format(Hours, "0") & ":"

End If

A = Format(Hours, "00") & ":"

A = A & Format(Minutes, "00") & ":"

A = A & Format(Seconds, "00")

A = A & Format(Tenths, ".00")

Elasped_Time = A

End Function

The A97 help file on the '\' operator states:

Before division is performed, the numeric expressions are rounded to

Byte, Integer, or Long expressions.

IMO, the easiest way to fix your current code is always to use the

Int() function prior to using '\' to prevent rounding up by chopping

the decimal part, effectively rendering the rounding ineffective:

Minutes = (Int(TimeElapsed) \ 60) Mod 60

instead of

Minutes = (TimeElapsed \ 60) Mod 60

I tried this out for the situation you gave. It seemed to do the right

thing. Thanks for pointing out this behavior. I have some code to

check.

James A. Fortune

CD********@FortuneJames.com
Jim, you have a natural gift for learning languages. I think I can

have you speaking Mandarin better than I speak English within a year.

By the way, in China there's a complete philosophy centered on tea

preparation. Most of it is grown in the high mountains. There are a

lot of special teas. Why are you laughing? -- Boxiang