turacek

Layer List recursion

Discussion created by turacek on Jul 20, 2010
Latest reply on Aug 4, 2010 by turacek
I have this code:

Sub zoznamvrstiev()
    Dim pmxdoc As IMxDocument
        Dim pMap As iMap
        Dim pFeatureLayer As IFeatureLayer
        Dim pFeatureClass As IFeatureClass
        Set pmxdoc = ThisDocument
        Set pMap = pmxdoc.FocusMap
        Dim pEnumLayer As IEnumLayer
        Dim pId As New uid

Dim a As String
a = pMap.name & ":"

    Dim b As String
    Dim player As ILayer
Set pMap = pmxdoc.FocusMap
     pId.value = "{34C20002-4D3C-11D0-92D8-00805F7C28B0}" ' = ILayer
     'pId.value = "{BA119BC4-939A-11D2-A2F4-080009B6F22B}" ' = iComposite
     'pId = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" ' = Igeofeaturelayer
    Set pEnumLayer = pMap.LAyers(pId, True)
    pEnumLayer.Reset
    Set player = pEnumLayer.Next

    Do Until player Is Nothing

    b = b + player.name + ":"

    Dim colection As New Collection
    Dim out As Variant
    Dim c As String
    c = a + b + Chr(13)
    out = c
    colection.Add out
    Set player = pEnumLayer.Next
   
Loop
   
    For Each out In colection
    List = List & out
    Next
    MsgBox a + Chr(13) + List

End Sub
'Private Function Rekursia(player As ILayer)
'  Dim pFeatureLayer As IFeatureLayer
'  Dim pGroup As IGroupLayer
'  Dim pComp As ICompositeLayer
'  Dim i As Long
'  Dim pMap As iMap
'  Dim pmxdoc As IMxDocument
'  Set pmxdoc = ThisDocument
'  Set pMap = pmxdoc.FocusMap
'
'  'Dim i As Integer
'  If TypeOf player Is IGroupLayer Then
'    Set pComp = player
'    For i = 0 To pComp.Count - 1
'        'Rekursia pComp.Layer(i)
'     'MsgBox pComp.Layer(i).name
'    Next i
'
'  Else
'    If (TypeOf player Is IGeoFeatureLayer) Then
'      Set pFeatureLayer = player  'Pre FeatureLayer
'      For i = 0 To pMap.LayerCount - 1
'      'Rekursia pMap.Layer(i)
'
'      Next i
'      'MsgBox pFeatureLayer.name
'    End If
'
'  End If
'MsgBox player.name
'End Function



Its make a list of layers.But its make mistakes. I dont know how to set up the code in way to do what i want.
Its repeating the layername and i dont know why.
Somebody told me that i must do that by recursion.But i dont know how.
In my code is Recursion Function only for your help. I somebody can help me , ill be very thankfull.

Outcomes