Hi, here is the code. As I said, this runs fine but does not retain the cursor or the 'layer no' i specify when it is run again.
#Region "Zoom through features in nominated Layer"
'''<summary>Zooms to the selected layer in the TOC associated with the active view.</summary>
'''
'''<param name="mxDocument">An IMxDocument interface</param>
'''
'''<remarks></remarks>
Public Sub ZoomThruLayer(ByVal mxDocument As IMxDocument)
If mxDocument Is Nothing Then
Return
End If
' Get the map
Dim activeView As IActiveView = mxDocument.ActiveView
' ask the user for the layer's number in the Table Of Contents
Dim LayerNo As String
If LayerNo = "" Then
LayerNo = InputBox("Enter the layer number in the TOC for the layer to process." _
& vbNewLine & "Remember to start counting at 0.")
End If
' Select the required layer to cycle thru features of (post-proc putput layer)
Dim pFeatureLayer As IFeatureLayer
pFeatureLayer = mxDocument.FocusMap.Layer(CInt(LayerNo))
' is this the first time through?
Dim m_pFeatCur As IFeatureCursor
Dim testVal As String
If m_pFeatCur Is Nothing Then
m_pFeatCur = pFeatureLayer.Search(Nothing, False)
Else
'Use messages to find cause of error - not working though!
MessageBox.Show("Cursor WAS found!")
End If
' get the next feature
Dim pFeat As IFeature
pFeat = m_pFeatCur.NextFeature
If pFeat Is Nothing Then
m_pFeatCur = Nothing
Exit Sub
End If
' select the next feature
Dim pFeatureSelection As IFeatureSelection
pFeatureSelection = pFeatureLayer
With pFeatureSelection
.Clear()
.Add(pFeat)
End With
' Zoom to the feature
Dim pTopoOp As ITopologicalOperator
pTopoOp = pFeat.ShapeCopy
activeView.Extent = pTopoOp.Buffer(25).Envelope
' set map scale
'-------------------------------------------------------------
'Uncomment the line below and change the scale to whatever you want
'if you want to see the selected features at a set scale each time.
' mxDocument.FocusMap.MapScale = 1000
'-------------------------------------------------------------
' Refresh the map
activeView.Refresh()
End Sub
#End Region