I use the following nested loops to read the first point feature of a dataset and the rest points in that dataset. Then read the second point feature of a dataset and the rest points in that dataset and so on. The problem with these nested loops is that it reads the first point and the rest points only once. Why this happens?

Dim pFCursor As IFeatureCursor
Set pFCursor = pFeatureClass.Search(Nothing, True)

Dim pFCursor2 As IFeatureCursor
Set pFCursor2 = pFeatureClass.Search(Nothing, True)

Dim pFeature As IFeature
Dim pFeature2 As IFeature

Dim pPointA As IPoint
Dim pPointB As IPoint

Set pFeature = pFCursor.NextFeature
Do Until pFeature Is Nothing

Set pPointA = pFeature.Shape

MsgBox pFeature.Value(intPosFID) & "F1"

   Set pFeature2 = pFCursor2.NextFeature
   Do Until pFeature2 Is Nothing

         Set pPointB = pFeature2.Shape

         MsgBox pFeature2.Value(intPosFID) & "F2"

   Set pFeature2 = pFCursor2.NextFeature

 Set pFeature = pFCursor.NextFeature

The explanation is over on the ICursor interface (which FeatureCursor implements). You need to move Set pFCursor2 = pFeatureClass.Search(Nothing, True) into your first loop. Or set your recycling cursor to false, make one pass over your pFCursor2 cursor to create a collection of IFeature (List, Dictionary, etc) and then iterate over the collection.


Cursors are forward only; they do not support backing up and retrieving rows that have already been retrieved or making multiple passes over data. If an application needs to make multiple passes over the data, the application needs to reexecute the query that returned the cursor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.