UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> DDMMSStoDD    


Synopsis

This function converts a Degrees, Minutes and Seconds value to a Decimal Degrees value. For example, 17°30'34" to 17.5094444444444

CODE
' DDMMSStoDD
' http://www.utteraccess.com/wiki/DDMMSStoDD
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' rev  date                          brief descripton
' 1.0  2010-11-09                    
'
Public Function DDMMSStoDD(sDDMMSS As String) As Double
' This function converts a Degrees, Minutes, Seconds value
' to a Degrees Decimal Value.
'
' The input must contain be in this format:
'   #°#'#"
'   The Minutes (') and Seconds (") are optional
'

 Dim iDeg As Integer
 Dim iMin As Integer
 Dim iSec As Integer
 
 Dim iDegPos As Integer
 Dim iMinPos As Integer
 Dim iSecPos As Integer
 
 iDegPos = InStr(1, sDDMMSS, Chr(176))
 iMinPos = InStr(1, sDDMMSS, "'")
 iSecPos = InStr(1, sDDMMSS, """")
 
 If iDegPos = 0 Then
   iDeg = 0
 Else
   iDeg = Int(Left(sDDMMSS, iDegPos - 1))
 End If
 
 If iMinPos = 0 Then
   iMin = 0
 Else
   iMin = Int(Mid(sDDMMSS, iDegPos + 1, iMinPos - 1 - iDegPos))
 End If
 
 If iSecPos = 0 Then
   iSec = 0
 Else
   iSec = Int(Mid(sDDMMSS, iMinPos + 1, iSecPos - 1 - iMinPos))
 End If
 
 DDMMSStoDD = iDeg + (iMin / 60) + (iSec / 3600)

End Function

Creative Commons License
DDMMSStoDD by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 3,657 times.  This page was last modified 08:28, 6 April 2011 by Jack Leach.   Disclaimers