Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assistance with Days, Hours, Minutes 1

Status
Not open for further replies.

powerpro

Technical User
Dec 23, 2003
9
US
I have searched numerous threads and tried many suggestions, but I'm still having problems.

Have a field where i enter the gallons of fuel available [Gallons]

Have another field where I enter the engine's fuel consumption per hour [PerHour]

Have an unbound text box for the results of [Gallons] divided by [PerHour]


Here lies the problem, how can I have the results return in Days, Hours, Minutes?

As an example:

35 gallon tank
1.24 gallons per hour

results are: 28.22581

I can figure how to get hours and minutes from this result, but the example above is a conservative one. I do have 3,000 gallon tanks with a fuel consumption of 3 gallons per hour at other sites.

It would also be great to have the result state it such as 1 Day, 7 Hours, 35 Minutes.

Any help would be greatly appreciated...I love the tons of info here.
 
You'll need a function to return the result you want, like:

Function HoursToText(InVal As Variant) As Variant

Dim D, H, M As Long
Dim RetVal As Variant

If Nz(InVal, 0) = 0 Then
HoursToText = Null
Else
D = Int(InVal / 24)
H = InVal Mod 24
M = Round((InVal - Int(InVal)) * 60)
RetVal = D & " day" & IIf(D = 1, ", ", "s, ")
RetVal = RetVal & H & " hour" & IIf(H = 1, ", ", "s, ")
RetVal = RetVal & M & " minute" & IIf(M = 1, "", "s")
HoursToText = RetVal
End If

End Function

Then a textbox with its ControlSource set to =HoursToText(me!txtResult) where txtResult is the name of your result calc control. At least it's one way to do it, I'm sure there are other solutions.

Ken
 
Hi,

Simple: Convert Hours to Days (div by 24) and then format
Code:
Format((([Gallons] / [PerHour]) / 24), "[h]:nn")
[code]


Skip,
[sub]
[glasses] [b][red]Be advised:[/red][/b] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
[b]Neopolitan Blownapart![/b] [tongue][/sub]
 
Thank you so much for both of your responses.

sfm6s524 yours works like a charm!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top