AK_Beaver
02-02-2017, 07:02 PM
Hi, I'm new to this site and figured it might be a good place to get some help. I'm trying to format my DD to DMS VBA code so that the out put is 00-00-00. If the number is less then 10, I need the number to lead with a 0, such as 01, 02, etc. I have tried every formatting concept I know, which isn't a lot because I'm new to VBA. I'd appreciate any help you can give. Thank You!
Here's my code with test function (It runs great in its current form, its just the wrong format):
---------------------------------------------------------------------------------------------------
Function DD2DASH(dDDAngle As Double) As String
'Converts DD angles to DMS angles in dash format
Dim dDegrees As Double
Dim dMinutes As Double
Dim dSeconds As Double
'Find Degrees
dDegrees = Int(dDDAngle)
'Find Minutes
dMinutes = (dDDAngle - dDegrees) * 60
'Find Seconds
dSeconds = Format(((dMinutes - Int(dMinutes)) * 60), "00.00000000")
'Convert to DMS in dash form and return value
DD2DASH = dDegrees & "-" & Int(dMinutes) & "-" & dSeconds
End Function
--------------------------------------------------------------------------------------------
Sub Test_DD2Dash()
Dim MyDD2DASH As String
MyDD2DASH = DD2DASH(8.705)
Debug.Print MyDD2DASH
End Sub
Here's my code with test function (It runs great in its current form, its just the wrong format):
---------------------------------------------------------------------------------------------------
Function DD2DASH(dDDAngle As Double) As String
'Converts DD angles to DMS angles in dash format
Dim dDegrees As Double
Dim dMinutes As Double
Dim dSeconds As Double
'Find Degrees
dDegrees = Int(dDDAngle)
'Find Minutes
dMinutes = (dDDAngle - dDegrees) * 60
'Find Seconds
dSeconds = Format(((dMinutes - Int(dMinutes)) * 60), "00.00000000")
'Convert to DMS in dash form and return value
DD2DASH = dDegrees & "-" & Int(dMinutes) & "-" & dSeconds
End Function
--------------------------------------------------------------------------------------------
Sub Test_DD2Dash()
Dim MyDD2DASH As String
MyDD2DASH = DD2DASH(8.705)
Debug.Print MyDD2DASH
End Sub