For example when converting -10.77538872 South it responds with -010° 46' 31.3994" when I'm expecting -10 46' 31.3994".
What I'm seeing is that ConvertDegrees() takes a latitude input of -10.77538872 and converts it to 010° 46' 31.3994"S
i.e. no 'South' on the input but a positive DMS with an 'S' for southern latitude
I'm guessing that you want
Latitudes
-10.77538872 to convert to 10°46'31.3994"S
+10.77538872 to convert to 10°46'31.3994"N
Longitudes
-110.77538872 to convert to 10°46'31.3994"W
+110.77538872 to convert to 10°46'31.3994"E
The original logic to select lat or long was a little convoluted so I changed it. The rest is basically the same
Sub test()
MsgBox ConvertDegrees(10.77538872, -1) ' E Longitude
MsgBox ConvertDegrees(-10.77538872, -1) ' W Longitude
MsgBox ConvertDegrees(179.77538872, -1) ' E Longitude
MsgBox ConvertDegrees(-179.77538872, -1) ' W Longitude
MsgBox ConvertDegrees(10.77538872, 1) ' N latitude
MsgBox ConvertDegrees(-10.77538872, 1) ' S latitude
MsgBox ConvertDegrees(89.77538872, 1) ' N latitude
MsgBox ConvertDegrees(-89.77538872, 1) ' S latitude
MsgBox ConvertDegrees(45, 0) ' azumuth
MsgBox ConvertDegrees(-45, 0)
End Sub
' Converts decimal latitude, longitude or azimuth value to degrees/minutes/seconds string format
' ConvType = -1 Longitude, = 0 Azumuth, = 1 Latitude
Public Function ConvertDegrees(ByVal decimalDeg As Double, Optional ConvType As Long = -1) As String
Select Case ConvType
Case -1 ' longitude
decimalDeg = NormalizeLon(decimalDeg)
Case 1 ' Latitude
decimalDeg = NormalizeLat(decimalDeg)
Case 0 ' azimuth
decimalDeg = NormalizeAzimuth(decimalDeg, True) ' 0 - 360
End Select
Dim s As Integer: s = Sign(decimalDeg)
decimalDeg = Abs(decimalDeg)
Dim degrees As Integer: degrees = Fix(decimalDeg)
Dim minutes As Integer: minutes = Fix((decimalDeg - degrees) * 60)
Dim seconds As Double: seconds = Round((decimalDeg - degrees - (minutes / 60)) * 60 * 60, 4) ' 4 digit precision corresponds to ~3mm
Select Case ConvType
Case -1
ConvertDegrees = Format$(degrees, "##0") & Chr$(176) & Format$(minutes, "00") & "'" & Format$(seconds, "00.0000") + Chr$(34)
If s = 1 Then
ConvertDegrees = ConvertDegrees + "E"
ElseIf s = -1 Then
ConvertDegrees = ConvertDegrees + "W"
End If
Case 1
ConvertDegrees = Format$(degrees, "#0") & Chr$(176) & Format$(minutes, "00") & "'" & Format$(seconds, "00.0000") + Chr$(34)
If s = 1 Then
ConvertDegrees = ConvertDegrees + "N"
ElseIf s = -1 Then
ConvertDegrees = ConvertDegrees + "S"
End If
Case 0
ConvertDegrees = Format$(degrees, "##0") & Chr$(176) & Format$(minutes, "00") & "'" & Format$(seconds, "00.0000") + Chr$(34)
If s = -1 Then ConvertDegrees = "-" + ConvertDegrees
End Select
End Function