USForestServiceAdmin

Calc Acres using an update cursor

Discussion created by USForestServiceAdmin on Apr 12, 2010
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

Outcomes