Problem with Conditional Formating 
Author Message
 Problem with Conditional Formating

Hello.  I am using the VB code detailed below to calculate
and display an elapsed time in a form.  I am having
difficulty getting a conditional format to work when the
resulting value is greater than 14 hours and 00 minutes.

Doesn't 14 hrs. 00 min. = 0.583333333328483?

? CDbl (#12/14/2002 14:01:00#-#12/14/2002 00:01:00#)
 0.583333333328483

Maybe I am doing something wrong here.  Any ideas?

Thanks,

Brian

Function GetElapsedTime(interval)
  Dim LngHours As Long, LngMinutes As Long

  If IsNull(interval) Then
    GetElapsedTime = 0
  Else
    LngHours = Int(interval * 24)
    LngMinutes = Int(interval * 1440) Mod 60

    GetElapsedTime = LngHours & "  Hours " & LngMinutes
& " Minutes"
  End If

End Function



Tue, 21 Sep 2004 14:53:24 GMT  
 Problem with Conditional Formating
That's a normal result of the inherent imprecision of
floating point numbers Brian.

Try adding a half second (approx. 6E-6) to interval to help
deal with the "rounding error".

        LngHours = Int((interval + 6E-6) * 24)
        LngMinutes = Int((interval + 6E-6) * 1440) Mod 60

Marsh

On Thu, 4 Apr 2002 22:53:24 -0800, "Brian"

Quote:

>Hello.  I am using the VB code detailed below to calculate
>and display an elapsed time in a form.  I am having
>difficulty getting a conditional format to work when the
>resulting value is greater than 14 hours and 00 minutes.

>Doesn't 14 hrs. 00 min. = 0.583333333328483?

>? CDbl (#12/14/2002 14:01:00#-#12/14/2002 00:01:00#)
> 0.583333333328483

>Maybe I am doing something wrong here.  Any ideas?

>Thanks,

>Brian

>Function GetElapsedTime(interval)
>  Dim LngHours As Long, LngMinutes As Long

>  If IsNull(interval) Then
>    GetElapsedTime = 0
>  Else
>    LngHours = Int(interval * 24)
>    LngMinutes = Int(interval * 1440) Mod 60

>    GetElapsedTime = LngHours & "  Hours " & LngMinutes
>& " Minutes"
>  End If

>End Function

Marsh


Tue, 21 Sep 2004 22:27:51 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Conditional Formating Problem.

2. Conditional Formating

3. Conditional Formating Substitute for Access 97

4. Conditional formating

5. Conditional Formating..with code?

6. Conditional formating of templates in Word 97

7. currentfieldvalue and conditional field formating in a cross-tab

8. Conditional formating for datagrid

9. Problem in formating when outputting report to excel

10. RTF formating is a problem

11. problem with number formating

12. Problems with conditional suppression

 

 
Powered by phpBB® Forum Software