How to run this script for all segment layer through loop

Discussion created by monalakade84 on Apr 7, 2010
Hello Alls

               Here I am sending code for common end point between two line segment but now I want to run this code for all segment layer through loop. so please suggest me where I should use loop to run this code for all segment.

Sub FindToNode()

Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pFlayer As IFeatureLayer
Dim pFsel As IFeatureSelection
Dim pSelset As ISelectionSet
Dim pFeature As IFeature
Dim pFCur As IFeatureCursor
Dim pPolyline As IPolyline
Dim ppolyline2 As IPolyline
Dim pPoint As IPoint
Dim pPointcollection As IPointCollection
Dim p1 As IPoint
Dim p2 As IPoint
Dim pGCont As IGraphicsContainer
Dim pGrlayer As IGraphicsLayer
Dim pMelement As IMarkerElement
Dim pElement As IElement
Dim pActive As IActiveView

'Get the current map
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap

'Get the first layer in the map
Set pFlayer = pMap.Layer(0)

'Get the selected features from the layer
Set pFsel = pFlayer
Set pSelset = pFsel.SelectionSet

'Make sure that feature is selected
If pFsel.SelectionSet.Count < 1 Then
MsgBox "Please select feature"
Exit Sub
End If

pSelset.Search Nothing, False, pFCur
Set pFeature = pFCur.NextFeature

Set pPolyline = pFeature.Shape
Set pFeature = pFCur.NextFeature
Set ppolyline2 = pFeature.Shape
Set p1 = pPolyline.ToPoint
Set p2 = ppolyline2.ToPoint

Set pGrlayer = pMap.BasicGraphicsLayer
Set pGCont = pGrlayer
Set pActive = pMxDoc.ActiveView
Set pPointcollection = pPolyline

'For i = 0 To pPointcollection.PointCount - 1

'Set pPoint = pPointcollection.Point(pPointcollection.PointCount - 1)
'Set pPoint = pPointcollection.Point(pPointcollection.PointCount - 1)

'To get common End point node
If (p1.x = p2.x) And (p1.y = p2.y) Then
Set pMelement = New MarkerElement
Set pElement = pMelement
pMelement.Symbol = New SimpleMarkerSymbol
pElement.Geometry = p1
pGCont.AddElement pElement, 0
MsgBox "Check Direction"
Exit Sub
End If

If (p1.x = p2.y) And (p1.y = p2.x) Then
Exit Sub
End If
MsgBox "No Error"

End Sub