TRICKY math problem ... need help

  • Thread starter Thread starter margieinWY
  • Start date Start date
M

margieinWY

Guest
I am trying to convert latitude and longitude coordinates from decimal degrees to DDMMSS(Degrees, Minutes, Seconds) through the "on exit" event procedure in a form.

I have a table with columns:
latitude - holds decimal lat
longitude - holds decimal lon
dlat - holds the converted ddmmss lat
dlon - holds the converted dddmmsslon

I have tried the following formula BUT, I think that I am using "int" incorrectly in the "sec" definition. (The "min" function gives me the proper number but the 1st "sec" function gives me "00".) I need to get just the decimal part of the "min" and instead of using int is there anything else that will round the number?

Private Sub LATITUDE_EXIT(Cancel As Integer)
Dim Deg, Min, Sec As Integer
' Get the Degrees
Deg = Int(LATITUDE)
' Get the Minutes
Min = (LATITUDE - Deg) * 60
' Get the Seconds and make sure to round
Sec = Min - (Int(Min))
Sec = Int((Sec * 60) + 0.5)
' Put them together and store in DLAT
DLAT = (Deg * 10000) + (((int(Min)) * 100) + Sec
End Sub

All of the fields in the table and form are "double, fixed, at 6 decimal places."

If anyone has a clue I would greatly appreciate any help ... be careful though, the more you think about it, the more confused this equation seems
smile.gif
.

Thanks in advance...

MARGE
 
Marge,

The reason that you are getting zero for seconds is because "min" and "sec" are declared as integers. So Sec = Min - int(min) returns zero, because min is already equal to int(min). Declare them as doubles and you should be fine. Hope that helps.

Doug
 
Doug ...

THANK YOU, THANK YOU, THANK YOU!!! I had no idea what declaring As Integer meant, I just saw a similar function do that. It works perfectly now!

GREAT JOB and THANKS again!!!
smile.gif


Marge
 

Users who are viewing this thread

Back
Top Bottom