The following line is creating the above error message.
tree_nodes((lev el)-1).Nodes.Add(tr ee_nodes(level) )
It's because of the following line where I'm trying to calculate the length of
blank spaces and substracting from total length.
level = text_line.Lengt h - text_line.TrimS tart.Length
Here's the code. The first part of the "IF" is fine.
Dim stream_reader As New System.IO.Strea mReader(file_na me)
Dim file_contents As String = stream_reader.R eadToEnd()
stream_reader.C lose()
' Remove line feeds.
file_contents = file_contents.R eplace(vbLf, "")
' Break the file into lines.
Const charCR As Char = CChar(vbCr)
'Const charTab As Char = CChar(vbTab)
Dim lines() As String = file_contents.S plit(charCR)
' Process the lines.
Dim text_line As String
Dim level As Integer
Dim tree_nodes() As Microsoft.Web.U I.WebControls.T reeNode
Dim num_nodes As Integer = 0
ReDim tree_nodes(num_ nodes)
trv.Nodes.Clear ()
For i As Integer = 0 To lines.GetUpperB ound(0)
text_line = lines(i)
If text_line.Trim( ).Length > 0 Then
' See how many tabs are at the start of the line.
level = text_line.Lengt h - text_line.TrimS tart.Length
' Make room for the new node.
If level > num_nodes Then
num_nodes = level
ReDim Preserve tree_nodes(num_ nodes)
End If
' Add the new node.
If level = 0 Then
'tree_nodes(lev el) = trv.Nodes.Add(t ext_line.Trim() )
tree_nodes(leve l) = New TreeNode
tree_nodes(leve l).Text = CStr(text_line. Trim())
trv.Nodes.Add(t ree_nodes(level ))
Else
' tree_nodes(leve l) = tree_nodes(leve l -
1).Nodes.Add(te xt_line.Trim())
tree_nodes(leve l) = New TreeNode
tree_nodes(leve l).Text = CStr(text_line. Trim())
tree_nodes((lev el)-1).Nodes.Add(tr ee_nodes(level) )
End If
I'm reading from a file that has indentation based on spaces. If it was a
true tab-delimited file I would be okay. So, it's the blank spaces that
would determine order of the nodes. Thanks in advance.
--
Hutty