Migrating VB script for Arc10

Discussion created by mpc on Mar 31, 2011
Latest reply on Apr 28, 2011 by mpc
I didn't actually write this script and I'm far more familiar with Python and haven't done any VB. In Python the equivalent outcome takes far too long, so I need to implement this instead as time is of the essence.

The error I get using Field Calculator is "Expected end of statement". Any ideas on what's wrong? I gather in Arc10 'Dim count as Long' gets changed to 'Dim count'. Aside from that my knowledge is lacking :(

Thanks in advance!

'** Declare variable to store population sum in
Dim count As Long

'** Get pointer variables to current arcmap project
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap

'** Get pointer variable to the polygon layer for which you wish 
'** to count the # of intersects from
Dim pCountLayer As IFeatureLayer

'SET THIS...At the moment the "CountLayer" 
'must be FIRST in ArcMap TOC
Set pCountLayer = pMap.Layer(0)

'** Set up a spatial filter and feature cursor to select
'** all polygons that interest the current layer's midpoint
'** and iterate through results to produce a count

Dim pSpatialFilter As ISpatialFilter
Dim pFCursor As IFeatureCursor
Dim pFeature As IFeature
Dim pPolygon As IPolygon
Dim pMidPoint as IPoint
Dim pArea as IArea
Set pArea = [Shape]
Set pMidPoint = pArea.labelpoint

Set pSpatialFilter = New SpatialFilter
Set pSpatialFilter.Geometry = pmidpoint
pSpatialFilter.SpatialRel = esriSpatialRelIntersects

Set pFCursor = pCountLayer.Search(pSpatialFilter, True)
Set pFeature = pFCursor.NextFeature

'** iterate through selected polygons to count for each 
'** polygon to be analyzed
Count = 0
Do Until pFeature Is Nothing
  Count = Count + 1
  Set pFeature = pFCursor.NextFeature