Is This Content Helpful?
We're glad to know this article was helpful.
This article contains sample code that adds a field called Area to your polygon attribute table and populates it with the area for each polygon.
Note: For more information on creating a UIControl, see the ArcGIS Desktop Help topic "Creating custom commands with VBA and UI Controls"
Code: Dim pDoc As IMxDocument Dim pMap As IMap Set pDoc = ThisDocument Set pMap = pDoc.FocusMap '-- Get the selected layer Dim pFLayer As IFeatureLayer Set pFLayer = pDoc.SelectedLayer Dim pFc As IFeatureClass Set pFc = pFLayer.FeatureClass '-- Check to see if layer already has an area field If Not pFc.FindField("Area") = -1 Then MsgBox "Area already exists" Exit Sub End If '-- Create a field called Area Dim pField As IField Set pField = New Field Dim pFieldEdit As IFieldEdit Set pFieldEdit = pField With pFieldEdit .Name = "Area" .Type = esriFieldTypeDouble .Precision = 11 .Length = 12 .Scale = 3 End With pFc.AddField pField '-- Loop through the features and get the area Dim pFCursor As IFeatureCursor Set pFCursor = pFLayer.Search(Nothing, False) Dim pFeat As IFeature Set pFeat = pFCursor.NextFeature Do Until pFeat Is Nothing Dim pArea As IArea If pFeat.Shape.GeometryType = esriGeometryPolygon Then Set pArea = pFeat.Shape pFeat.Value(pFc.FindField("Area")) = pArea.Area pFeat.Store End If Set pFeat = pFCursor.NextFeature Loop
Note: The selected layer should not have an existing field called area