AnsweredAssumed Answered

For loop problem

Question asked by davecouture on Jul 16, 2012
Latest reply on Jul 16, 2012 by davecouture
I'm trying to figure out what is wrong with my For loop. To make it easy, I stripped down the code and this is what it supposed to do:

- Make sure there are Single Tables in TOC (if true, continue)
- Check if the Subdivision Plans table is in TOC.
- If Subdivision Plans table is in TOC, show "Subdivision Plans Table Found" message
- If Subdivision Plans table is not in TOC, show "Subdivision Plans Table Not Found" message

If the Subdivision Plans table is in the TOC, everything works as it should. But, if the Subdivision Plans table isn't found, it goes to the Catch Exception error, instead of the "Subdivision Plans Table Not Found" message. Why?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            ' Variables declarations
            Dim ANBLS As String = Me.ComboBox1.Text.Trim
            Dim pMap As IMap = My.ArcMap.Document.ActiveView
            Dim queryFilter As String = "FileNumber = '" + ANBLS + "'"
            Dim tableName As String = "CSJGISSDE.GISDATA.Subdivision_Plans_Table"
            Dim pStTabColl As IStandaloneTableCollection
            Dim foundTable As Integer = 0
            pStTabColl = pMap

            ' Check if there are tables are in TOC
            If pStTabColl.StandaloneTableCount <> 0 Then

                ' Check if Subdivision Plans table is in TOC
                For i As Integer = 0 To pStTabColl.StandaloneTableCount
                    If (pStTabColl.StandaloneTable(i).Name = tableName) Then
                        MsgBox("Subdivision Plans Table found")
                        foundTable = 1
                        Exit For
                    End If
                Next i
                MsgBox("No tables found")
            End If

            ' Subdivision Plans Table Not found in the TOC
            If foundTable = 0 Then
                MsgBox("Subdivision Plans Table Not found")
            End If

            ' If all fails...
        Catch ex As Exception
            MsgBox("This action cannot be done. Save your project, then restart ArcMap.")
        End Try
End Sub