1

I'm newbie and have question about string builder to show the arcgis layers. (System: ArcGis 10.2, VisualStudio2012) I don't succeed to show the loaded layers in a line of the message box.

code:

Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.ArcMapUI
Imports System.Text

Public Class LayerLoop2_Button1
  Inherits ESRI.ArcGIS.Desktop.AddIns.Button

  Public Sub New()    
  End Sub

  Protected Overrides Sub OnClick()
        AccessLayerViaMxDocument(My.ArcMap.Document)
        My.ArcMap.Application.CurrentTool = Nothing
  End Sub

    Shared Sub AccessLayerViaMxDocument(ByVal pMxDocument As IMxDocument)
        Dim pMap As IMap
        Dim pMaps As IMaps = pMxDocument.Maps
        Dim i As Integer

        For i = 0 To pMaps.Count - 1 Step i + 1
            pMap = pMaps.Item(i)
            Debug.WriteLine(pMap.Name)
            MsgBox(pMap.Name)

            Dim pEnumLayer As IEnumLayer = pMap.Layers(Nothing, True)
            pEnumLayer.Reset()
            Dim pLayer As ILayer = pEnumLayer.Next()
            Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()

            While Not pLayer Is Nothing

                Debug.WriteLine(pLayer.Name)
                ' Show MessageBox with the name of the layer
                pLayer = pEnumLayer.Next()

                sb.Append(pLayer.Name)
                MsgBox(sb.ToString())
            End While
        Next
    End Sub

Can you explain me please what you mean with console output? As output I should just have a message box. In the code above I tried already to use the string builder - but without success.... The first given code was this:

Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.ArcMapUI

Public Class AccessLayer

Inherits ESRI.ArcGIS.Desktop.AddIns.Button

Public Sub New()
End Sub

Protected Overrides Sub OnClick()

AccessLayerViaMxDocument(My.ArcMap.Document)
My.ArcMap.Application.CurrentTool = Nothing
End Sub

Shared Sub AccessLayerViaMxDocument(ByVal pMxDocument As IMxDocument)

Dim pMap As IMap
Dim pMaps As IMaps = pMxDocument.Maps

Dim i As Integer

For i = 0 To pMaps.Count - 1 Step i + 1
pMap = pMaps.Item(i)

Debug.WriteLine(pMap.Name)

MsgBox(pMap.Name)

Dim pEnumLayer As IEnumLayer = pMap.Layers(Nothing, True)
pEnumLayer.Reset()

Dim pLayer As ILayer = pEnumLayer.Next()
While Not pLayer Is Nothing
Debug.WriteLine(pLayer.Name)

MsgBox(pLayer.Name)

pLayer = pEnumLayer.Next()
End While

Next    
End Sub

Protected Overrides Sub OnUpdate()
Enabled = My.ArcMap.Application IsNot Nothing    
End Sub

End Class

closed as off-topic by PolyGeo Apr 19 '17 at 21:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Please edit the question to show the console output. There isn't much in the way of GIS content, as it seems to be a VB issue. – Vince Aug 1 '15 at 13:32
  • Hello and thank you for your attention! Can you explain me please what you mean with console output? As output I should just have a message box. – Susan Aug 3 '15 at 13:10
  • 1
    You've got "Debug.WriteLine" directives -- what are they doing? – Vince Aug 3 '15 at 13:15
  • If you're running it through the VS debugger, you should be able to add breakpoints in your code and stop it to check your values. If you don't know how to do that I would advise going a little internet searching or posting another question. – Branco Aug 3 '15 at 13:29
  • Thank you for answering that quick! The debug.writeline should be for the name of Map and layer. I know how to set breakpoints but honestly I'm not able to use the information from there. And as I'm not on visual studio now, I can't tell you any message of failure... – Susan Aug 3 '15 at 13:38

Browse other questions tagged or ask your own question.