0

cfg file to start, this is the file:

http://pastebin.com/mE3Y3wiq

What I am doing is looking for a class, once found I store the data for THAT class in a listbox, so ex: if I'm looking for "Fixing", I will store each line in a listbox that is after "{Fixing}" until we hit the next class OR the end of the file (for Fixing we would stop at "{Pillars}")

Here is my code:

Private Sub tvList_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles tvList.AfterSelect
        Dim cfgData() As String
        ' Dim lstData As New ListBox()

        lstData.Items.Clear()

        If rbnInch.Checked Then
            cfgData = File.ReadAllLines("C:\Library\Common\PARAM-NG\Dbs\Mould\Dme_I\Dme_I.cfg")
        Else
            cfgData = File.ReadAllLines("C:\Library\Common\PARAM-NG\Dbs\Mould\Dme\Dme.cfg")
        End If

        Dim classID As Short = tvList.SelectedNode.Index
        Dim classType As String = tvList.Nodes.Item(classID).Text

        Try
        For i As Short = 0 To cfgData.Count - 1
            If cfgData(i).Contains("{" & classType & "}") Or cfgData(i).Contains("{" & classType.Replace(" ", "") & "}") Then
                i += 1
                Do
                    lstData.Items.Add(cfgData(i))
                    i += 1
                    If cfgData(i).Contains(tvList.Nodes.Item(tvList.SelectedNode.Index + 1).Text.Replace(" ", "")) Or cfgData(i).Contains(tvList.Nodes.Item(tvList.SelectedNode.Index + 1).Text) Or cfgData(i).ToString() Is vbNullString Then
                        Exit Do
                    End If
                Loop
            End If
        Next
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

    End Sub

Right now I am only getting the first line in my listbox and that's it. Need help on collecting the data I need and then stopping at the next class or end of file (end of file for the last class since there is no class after it that will mark my exit)

2
  • 1
    set a breakpoint and execute each line one at a time to see which condition(s) are failing Commented Apr 10, 2015 at 12:44
  • 1
    Updated, I had a syntax error with my condition statement that is supposed to break the loop. Now it adds all items to the list, still not working. I want it to either detect the next class or the end of the file so it stops adding to the list. Commented Apr 10, 2015 at 12:57

1 Answer 1

2

This has been extracted from the question and posted on the OP's behalf.


I solved it myself.

Private Sub tvList_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles tvList.AfterSelect
    Dim cfgData() As String
    ' Dim lstData As New ListBox()

    lstData.Items.Clear()

    If rbnInch.Checked Then
        cfgData = File.ReadAllLines("C:\Library\Common\PARAM-NG\Dbs\Mould\Dme_I\Dme_I.cfg")
    Else
        cfgData = File.ReadAllLines("C:\Library\Common\PARAM-NG\Dbs\Mould\Dme\Dme.cfg")
    End If

    Dim classID As Short = tvList.SelectedNode.Index
    Dim classType As String = tvList.Nodes.Item(classID).Text

    Try
        For i As Short = 0 To cfgData.Count - 1
            If cfgData(i).Contains("{" & classType) Or cfgData(i).Contains("{" & classType.Replace(" ", "")) Then
                i += 1
                Do
                    If tvList.SelectedNode.Index + 1 >= tvList.Nodes.Count Then
                        If i >= cfgData.Count - 1 Then
                            lstData.Items.Add(cfgData(i))
                            Exit Do
                        ElseIf cfgData(i) = vbNullString Then
                            lstData.Items.Add(cfgData(i))
                            i += 1
                        ElseIf cfgData(i).Substring(0, 1).Contains("{") Then
                            Exit Do
                        Else
                            lstData.Items.Add(cfgData(i))
                            i += 1
                        End If
                    ElseIf i >= cfgData.Count - 1 Then
                        lstData.Items.Add(cfgData(i))
                        Exit Do
                    ElseIf cfgData(i) = vbNullString Then
                        lstData.Items.Add(cfgData(i))
                        i += 1
                    ElseIf cfgData(i).Substring(0, 1).Contains("{") Then
                        Exit Do
                    Else
                        lstData.Items.Add(cfgData(i))
                        i += 1
                    End If
                Loop
            End If
        Next
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.