Help construct a tree 1 -> 1.1 -> 1.2 -> 2 -> 2.1 -> 2.1.1 etc HELP!!!!!!!

M

Mos

Folks I need help. I have a Text file as follows: WITHOUT a control
just read and construct a tree

'1
2.1
1.1.1
1.1.1.1
2.2.1
1.3
2
Dim Parent() As String
Dim Level1() As String
Dim Level2() As String
Dim Level3() As String
etc ..


How can I construct a tree. parent, children, grand children etc...
and also figure out # of children # of grand children etc


Thanks


SEE CODE BELOW
Const Parents = 10
Const Level1 = Parents
Const Level2 = level1
Const Level3 = level2


Dim NodeParent() As String '1
Dim NodeLevel1() As String '1.1
Dim NodeLevel2() As String '1.1.1
Dim NodeLevel3() As String '1.1.1.1
Redim NodeParent(1 To Parents)
Redim NodeLevel1( 1 To Parents, 1 To Level1 )
Redim NodeLevel2( 1 To Level2 )
Redim NodeLevel3( 1 To Level3 )


Do While Not ( ThisDoc Is Nothing )
For i = 1 To Level3
For ii = 1 To Level2
For iii = 1 To Level1
If ThisDoc.SCBS(0) Like "#"
Then
NodeParent(iii) =
ThisDoc.SCBS(0)
Elseif ThisDoc.SCBS(0) Like
"#.#" Then
NodeLevel1(iii, ii) =
ThisDoc.SCBS(0)
Elseif ThisDoc.SCBS(0) Like
"#.#.#" Then


Elseif ThisDoc.SCBS(0) Like
"#.#.#.#" Then


End If
Next
Next
Next


Set ThisDoc = ThisView.GetNextDocument( ThisDoc )
Loop
 
J

James Hahn

It's already a tree, so what you do with it really depends on how you need
to access the items. For finding counts of items at particular levels, and
for iterating over those items a ListOf is probably simplest:

Dim ara As New List(Of String)
ara.Add("1")
ara.Add("2.1")
ara.Add("1.1.1")
ara.Add("1.1.1.1")
ara.Add("2.2.1")
ara.Add("1.3")
ara.Add("2")
Dim search As String = "1.1"
Dim a As New List(Of String)
a = ara.FindAll(Function(s As String) s.StartsWith(search))
MsgBox(search & vbCrLf & "Count = " & a.Count)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top