Question Problem with TreeView

vijay2482

Member
Joined
Apr 2, 2009
Messages
6
Programming Experience
Beginner
Hi all,

I have the below code that take a txt file as input and write the nodes of the tree at the end of the line.
VB.NET:
Using rdr As StreamReader = New StreamReader(inFile)
        Using wrt As StreamWriter = New StreamWriter(outFile)
            'read and write headers
            temp = rdr.ReadLine()
            pos = temp.IndexOf("BVS_COMPATIBILITY")
            wrt.WriteLine(temp & "  LINK_ID")
            wrt.WriteLine(rdr.ReadLine & "---------")

            'read and write first data line
            Dim theLine As New LinkIdDataItem(rdr.ReadLine, pos, 0)
            wrt.WriteLine(theLine.ToString)
            'read and write second data line 
            theLine = New LinkIdDataItem(rdr.ReadLine, pos, 1)
            wrt.WriteLine(theLine.ToString)
            levelOneSpaces = LeadingSpaces(theLine.modelName)
                prevLevelSpaces = levelOneSpaces
                highLinkId = 1
                While rdr.Peek > -1
                    theLine = New LinkIdDataItem(rdr.ReadLine, pos, 1)
                    If theLine.modelName.Trim.StartsWith("0") Then
                        theLine.linkId = 0
                    Else
                        currLevelSpaces = LeadingSpaces(theLine.modelName)
                        If currLevelSpaces > levelOneSpaces Then
                            If currLevelSpaces > prevLevelSpaces Then
                                highLinkId += 1
                                theLine.linkId = highLinkId
                            [COLOR="red"] Else
                                theLine.linkId = highLinkId
                                theLine.linkId += ((currLevelSpaces - prevLevelSpaces) \ 2)
                             End If  [/COLOR]                     
                        End If
                        End If
                    prevLevelSpaces = currLevelSpaces
                    wrt.WriteLine(theLine.ToString)
                End While
                PrintValues(myAL)
            End Using
        End Using
    End Sub

    Private Function LeadingSpaces(ByVal s As String) As Integer
        Dim i As Integer = 0
        While (i < s.Length) AndAlso (s.Chars(i) = " ")
            i += 1
        End While
        Return i
    End Function

    Class LinkIdDataItem
        Public modelName As String
        Public restOfLine As String
        Public linkId As Integer

        Sub New(ByVal s As String, ByVal p As Integer, ByVal id As Integer)
            modelName = s.Substring(0, p)
            restOfLine = s.Substring(p)
            linkId = id
        End Sub

        Public Overrides Function ToString() As String
            Return modelName & restOfLine & "  " & linkId.ToString("0000")
        End Function
    End Class

I need some help to replace the part of code in red color.
if the number of spaces before the current line < the number of spaces of the previous line, then
wrie the linkid of the current line should the linkid of the previous line, where the space before the the line is same.
eg: Output required:
VB.NET:
9999999		M91		0000
  2222222	M91		0001
    3333333	M91		0002
    4444444	M91		0002
      5555555	M91		0002
  2222222	M91		0001
    3333333	M1		0003
    4444444	M1		0003
    5555555	M91		0003
      6666666	M1		0004
 [COLOR="red"] 2222222	M91		0001[/COLOR]

eg: Output obtained which is not good:
VB.NET:
9999999		M91		0000
  2222222	M91		0001
    3333333	M91		0002
    4444444	M91		0002
    5555555	M91		0002
  2222222	M91		0001
    3333333	M1		0003
    4444444	M1		0003
    5555555	M91		0003
      6666666	M1		0004
[COLOR="red"]  2222222	M91		0003[/COLOR]
Thanks in advance for any help or suggestions.
 
Last edited:
Back
Top