You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects Visual Basic for Application (VBA) forum

Custom button to calculate acre   Prabu Pothiraj Jan 05, 2009
Re: Custom button to calculate acre   Ken Carrier Jan 05, 2009
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Custom button to calculate acre 
Author Prabu Pothiraj 
Date Jan 05, 2009 
Message Good Day

I want to add a custom button to calculate acre

and add it to the attribute table.

Any help would be apreciated.

Thanks

P.Prabu 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Custom button to calculate acre 
Author Ken Carrier 
Date Jan 05, 2009 
Message Here is some code I helped another person with and also the link to the forum posting

http://forums.esri.com/Thread.asp?c=93&f=992&t=270576&mc=9#836445

Hope this helps! 
 
Sub CalculateAcreage()

' You must be in an edit session for this to work

Dim pApp As IApplication
Dim pEditor As IEditor
Dim pID As New UID
pID = "esriCore.Editor"
Set pApp = Application
Set pEditor = pApp.FindExtensionByCLSID(pID)

pEditor.StartOperation
    
    Dim pFeature As IFeature
    Dim pEnumFeat As IEnumFeature
    Dim puid As New UID
    Dim lFld As Long
        puid.Value = "esricore.editor"
        
    Set pEditor = Application.FindExtensionByCLSID(puid)
    Set pEnumFeat = pEditor.EditSelection
        pEnumFeat.Reset
    Set pFeature = pEnumFeat.Next
    'I am assuming you are using SDE, if not change SHAPE.AREA to AREA.
        'lFld = pFeature.Class.FindField("SHAPE.AREA") >>>THIS IS ORIG<<<
        lFld = pFeature.Class.FindField("SHAPE_AREA")
    Dim i As Integer
    
    'This is your acreage field name in double quotes.
    'Dim Acres As Long >>>THIS IS ORIG<<<
    Dim Acres As Double
        'Acres = pFeature.Class.FindField("Acreage") >>>THIS IS ORIG<<<
        Acres = pFeature.Class.FindField("Polygon_Acres")
  For i = 0 To pEditor.SelectionCount - 1
    
     pFeature.Value(Acres) = pFeature.Value(lFld) / 43560
    
     pFeature.Store
     
     Set pFeature = pEnumFeat.Next
    
  Next i
    
pEditor.StopOperation "Update"

End Sub
 
  Ken Carrier
GIS Specialist
Montgomery County Ohio Water Services