UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Calculate Driving Time, Access 2013    
 
   
fogline
post Feb 5 2018, 10:08 AM
Post#1



Posts: 33
Joined: 5-August 15
From: Ringgold, GA.


Can anyone help me out with this??

I need to calculate Driving time:
I need to Divide Total Miles by Speed and get the Total Hours and Minutes it will take to drive.

I was trying this but not working: =[TravelTime]\60 & Format([TravelTime] Mod 60,"\.00")

Like this: 1655 / 55 = 30:45 Hours

What I would really like is: 1655 / 55 = 30 Hours 45 Minutes

Thanks for any help..
Go to the top of the page
 
GroverParkGeorge
post Feb 5 2018, 10:16 AM
Post#2


UA Admin
Posts: 32,778
Joined: 20-June 02
From: Newcastle, WA


TravelTime = [TravelTime]\60 & " Hours " & Format([TravelTime] Mod 60,"\.00") & " Minutes"

--------------------
Go to the top of the page
 
doctor9
post Feb 5 2018, 10:56 AM
Post#3


UtterAccess Editor
Posts: 18,324
Joined: 29-March 05
From: Wisconsin


fogline,

I -think- this should return the string you're looking for:

CODE
Public Function DriveTime(intTotalMiles As Integer, intMPH As Integer) As String

'   Total hours:
    DriveTime = intTotalMiles / intMPH
    
'   Hours and minutes:
    DriveTime = Int(DriveTime) & " Hours " & Round((DriveTime - Int(DriveTime)) * 60, 0) & " Minutes"

End Function


What threw me off was your example. Driving at 55mph for 30 hours 45 minutes should take you 1691.25 miles, not 1655. If I've got my maths wrong, please let me know. (30.75 * 55 = 1,691.25)

Dennis

--------------------
(;,;) Li'l Cthulu says: Please talk about what you're trying to do, as well as how you're doing it.
Changing your real table name to "Table1" and your real form name to "Form1" in your posts makes it more difficult to understand what's going on, not easier.
Guidelines for Posting Questions
Go to the top of the page
 
fogline
post Feb 5 2018, 11:21 AM
Post#4



Posts: 33
Joined: 5-August 15
From: Ringgold, GA.


Thanks for your help. I think I have it working now.

Function DrivingTime()

Dim TravelTime As Double
Dim TotalMiles As Double, Speed As Double

'example values as supplied
TotalMiles = 1655
Speed = 55

'TravelTime = TotalMiles / Speed
'Debug.Print TravelTime


DrivingTime = CInt(TotalMiles / Speed) & " hours " & CInt(60 * (TotalMiles Mod Speed) / Speed) & " minutes"
Debug.Print DrivingTime

End Function
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    18th June 2018 - 10:55 AM