ArcObjects Library Reference  (System)    

AngleFormat Example

  1. Copy the code below.
  2. In ArcMap, select Macros... from Tools | Macros (or press Alt-F8).
  3. Enter a new macro name and click the Create button.
  4. Paste the copied code into the code pane.
  5. Press F5 to run the macro.
[Visual Basic 6.0]
Sub AngleFormatExample() ' Create an AngleFormat object and set AngleFormat ' options through the IAngleFormat interface Dim pAngleFormat As IAngleFormat Set pAngleFormat = New AngleFormat With pAngleFormat .AngleInDegrees = True 'Input values are in degrees .DisplayDegrees = True 'Display formatted numbers in degrees End With ' Set NumericFormat options through the INumericFormat interface. ' This step is not necessary unless you want to change the ' INumericFormat default properties. Comment this block of ' code out to see how it changes the format! Dim pNumericFormat As INumericFormat Set pNumericFormat = pAngleFormat With pNumericFormat .AlignmentOption = esriAlignRight .RoundingOption = esriRoundNumberOfDecimals .AlignmentWidth = 16 .RoundingValue = 5 .ShowPlusSign = True .UseSeparator = False .ZeroPad = False End With ' The ValueToString & StringToValue methods are in the ' INumberFormat interface. QI for INumberFormat to ' use them. Dim pNumberFormat As INumberFormat Set pNumberFormat = pAngleFormat '= pNumericFormat could be used here as well ' Format some angular numbers in degree format Dim dValue As Double, sV2S As String, dS2V As Double For dValue = -180 To 180 Step 90 sV2S = pNumberFormat.ValueToString(dValue) dS2V = pNumberFormat.StringToValue(sV2S) MsgBox "ValueToString(" & dValue & ") = '" & sV2S & "'" & vbNewLine & _ "StringToValue('" & sV2S & "') = " & dS2V, , _ "AngleFormat - Degree Format" Next ' Display radian values. A degree-to-radian conversion takes ' place in the ValueToString method, and a radian-to-degree ' conversion takes place in the StringToValue method. pAngleFormat.DisplayDegrees = False For dValue = -180 To 180 Step 90 sV2S = pNumberFormat.ValueToString(dValue) dS2V = pNumberFormat.StringToValue(sV2S) MsgBox "ValueToString(" & dValue & ") = '" & sV2S & "'" & vbNewLine & _ "StringToValue('" & sV2S & "') = " & dS2V, , _ "AngleFormat - Radian Format" Next End Sub

[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button Language Filter in the upper-left corner of the page.