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
CDMAP...@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
Since the decimal values for that example are entered, what I
recommended applies. For the general case where the Double value is
calculated I'd say that a little extra caution is in order.
In:
http://groups.google.com/group/comp.databases.ms-access/msg/afc4df1d5d81c109?hl=en&
I said:
"... it's better to add a little bit of self-defensive margin for
floating point error."
Suppose for argument's sake that TimeElapsed is calculated from a
formula. The self-defensive margin can be realized in that situation
by adding some small value to TimeElapsed before using the Int
function.
Minutes = (Int(TimeElapsed + 0.001) \ 60) Mod 60
59.999 => 1
59.9989 => 0
Note that the same adjustment would need to be made in the expression
for Seconds so that 59.999 => 1 Minute 0 Seconds rather than 1 Minute
59 Seconds.
James A. Fortune
CDMAP...@FortuneJames.com