HOW TO
Instructions provided describe how to perform Frequency commands for numeric fields in ArcMap using VBA and ArcObjects. ArcInfo has a Frequency command that returns a list of unique code occurences and their frequency for numeric and text fields.
Note:
Code in the ThisDocument module will only run in the current map document. To store the code in all your map documents, open the Normal.mxt ThisDocument code module.
Code:
Sub TestHistogram()
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMap As IMap
Set pMap = pDoc.FocusMap
Dim pLayer As IFeatureLayer
Set pLayer = pMap.Layer(0)
Dim pTable As ITable
Set pTable = pLayer.FeatureClass
Dim pTableHistogram As ITableHistogram
Set pTableHistogram = New TableHistogram
Dim pHistogram As IHistogram
Set pHistogram = pTableHistogram
' Get values and frequencies for STATE_FIPS
' for the US Counties layer into a table histogram object
pTableHistogram.Field = "STATE_FIPS"
Set pTableHistogram.Table = pTable
Dim dataFrequency As Variant
Dim dataValues As Variant
pHistogram.GetHistogram dataValues, dataFrequency
' Loop through the values returned by GetHistogram
For i = LBound(dataValues) To UBound(dataValues)
Debug.Print dataValues(i) & " " & dataFrequency(i)
Next i
End Sub
Article ID:000004957
Get help from ArcGIS experts
Download the Esri Support App