Select to view content in your preferred language

Calc Acres using an update cursor

815
0
04-12-2010 12:47 PM
USFS_AGOLAdministrator
Deactivated User
Hello All,

I have a tool which intersects two polygon layers, then uses an update cursor to calc the acres on the intersected layer.  This works fine.  However, I have another tool on my toolbar which is making calls to the exact same code.  It makes it 3/4 of the way through, then bails on me.  If I take my second tool, and run it first, it goes all the way through no problem, and my first tool then will bail on my 3/4 of the way through.  The code I'm using follows.  Is there a better way I can be doing this?

pFeatureclass = pFlayer.FeatureClass

            lngIndx = pFeatureclass.Fields.FindField(strField)
            If lngIndx = -1 Then
                MsgBox(strField & "field not found!", MsgBoxStyle.Information, "MainMod_CalcAcres")
                Exit Sub
            End If

            pProgbar.Position = 0
            pStatusBar.ShowProgressBar("Calculating Acres...", 0, intFeatures, 1, True)

            'Get the first feature.
            pUpDFCursor = pFeatureclass.Update(Nothing, False)
            pFeature = pUpDFCursor.NextFeature

            'Loop through all features.
            Do Until pFeature Is Nothing

                'Step the progress bar.
                pStatusBar.StepProgressBar()

                pArea = pFeature.Shape
                dblArea = pArea.Area

                'Calculate Acres from Area.
                pFeature.Value(pFeature.Fields.FindField(strField)) = pArea.Area / 4046.85642

                'Update all features with newly calculated acres.
                pUpDFCursor.UpdateFeature(pFeature)
                pFeature = pUpDFCursor.NextFeature
            Loop
0 Kudos
0 Replies