AngleString

From Microstation VBA Wiki
Jump to: navigation, search

This function takes an angle in radians and returns a text string with a format something like 4°-04'-21.1" Note that the function Degrees(), like Radians(), is part of Microstation VBA, but not included in Microsoft VBA. It is easy enough to convert by multiplying degrees by Pi/180 or radians by 180/Pi. This function does not deal with negative values.

Function AngleString(angle As Double) As String

Dim Degree As Double    'whole number of degrees
Dim Minute As Double    'whole number of minutes
Dim Second As Double    'decimal number of seconds
Dim dAngle As Double    'angle in decimal degrees

dAngle = Degrees(angle + 0.00000001)
'Set degree to Integer of Argument Passed
Degree = Int(dAngle)

'Set minutes to 60 times the number to the right
'of the decimal for the variable Decimal_Deg
Minute = (dAngle - Degree) * 60

'Set seconds to 60 times the number to the right of the
'decimal for the variable Minute
Second = 60 * (Minute - Int(Minute))

'Returns the Result of degree conversion
'(for example, 10.46 = 10~ 27  ' 36")
AngleString = Format(Degree, "0") & "^-" & Format(Int(Minute), "00") _
    & "'-" & Format(Second, "00.0") + Chr(34)

End Function