List GDB Feature Classes

311
4
12-19-2013 10:01 AM
DaveCouture
New Contributor III
I'm using a VB.NET code found in the ESRI Resource Center to list the content of a GDB.  For some reasons, it's not working.  It hangs or I get an empty string value.

Here's my code:

Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.esriSystem
Imports System.Windows.Forms
Imports ESRI.ArcGIS.Geoprocessing
Imports ESRI.ArcGIS.Geoprocessor      

Public Sub test()

        Dim gp As New ESRI.ArcGIS.Geoprocessor.Geoprocessor
        gp.SetEnvironmentValue("workspace", "G:\Data\GDB\Production.gdb")
        Dim fcs As ESRI.ArcGIS.Geoprocessing.IGpEnumList = gp.ListFeatureClasses("*", "", "")
        Dim fc As String = fcs.Next()

        Do While fc <> ""
            fc = fc + vbNewLine + fcs.Next()
        Loop

        MsgBox(fc)

End Sub
0 Kudos
4 Replies
NeilClemmons
Regular Contributor III
Your loop condition is to loop while fc is not an empty string.  You're setting the value of fc inside the loop to an actual value, so it will never be an empty string.  This results in an infinite loop because your loop condition will always be true.  The only exception is when no feature class names are returned at all, in which case fc is an empty string to start with.  In this case, you get the empty string.  In the case of the infinite loop, you get the hang.
0 Kudos
DaveCouture
New Contributor III
Makes sense.  But, this is the code I found here, in the ESRI Developer Network: http://edndoc.esri.com/arcobjects/9.2/NET/74749fb9-9724-465f-9e1c-32c6faec1d5e.htm
0 Kudos
NeilClemmons
Regular Contributor III
Actually, that's not the code you found there at all.  The code at that link is this:

Do While fc <> ""

        Console.WriteLine(fc)
        fc = fcs.Next()

    Loop


You've modified that code to append the feature class name to the variable fc with each loop iteration.  This is why fc will never be an empty string and why you a running into an infinite loop.  The code at that link works because it assigns the feature class name to the variable fc instead of appending it.  When fcs.Next() returns an empty string, fc will be assigned an empty string and the loop will terminate.
0 Kudos
DaveCouture
New Contributor III
OK, thanks!  I'll create another string to append all the names.
0 Kudos