I am trying to count the number of rows in a feature class attribute table. I have declared a feature cursor which i want to use later in the code to do some processing and field value calculation. (In the code below pFClass was declared to the IFeatureClass interface)
Dim pCursor As IFeatureCursor
pCursor = pFClass.Search(Nothing, False)
Dim pFeature As IFeature
Set pFeature = pFCursor.NextFeature
Dim LngCounter As Long
Do Until pFeature Is Nothing
LngCounter = LngCounter + 1
Set pFeature = pCursor.NextFeature
LOOP
When i run this code to get the number of items in the table i use a msgbox to print the number to screen which is accurate. But then i Cannot reuse my pFeature because it is now nothing.
Other permutations i have tried include declaring 2 cursors and 2 IFeature objects and then using the first to get the total count and then the second to do subsequent calculations of the attribute table but to no avail. I looked at the ITable.rowCount but could not get that to work for me. I'd really appreciate some help on this.
Thanks
Best Answer
Firstly, you really shouldn't start any new development in VBA right now. ArcGIS 10.0 is the last version which supports VBA.
Coming to your question, I would use IFeatureClass.FeatureCount Method. This directly give you the number of features that satisfy your query. If you pass
Nothing
for the query, it will return the total number of features in your featureclass. You need no loop over features, which is a slow process.