"Mos" <lndebug@gmail.com> wrote in message
news:875cd1df-7605-45ab-9f7b-f1edec25d47b@r34g2000vbi.googlegroups.com...
> Folks I need help. I have a view or(Text file) as follows:
>
> '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
It might be easier if you did describe exatly what you are trying to do.
I am not sure I 100% understand what you are looking for. But I will
take a guess that you want to read data from (for example) a text file
which is organized in a hierarchy like that.
You could use a list, or actually a list of lists (even if you have to
put them in a class), or array of arrays (same thing there, put them in
a class).
Something like this:
Class NodeData ' This goes in (Declarations)
Public node() As Variant
End Class
Sub Initialize
Dim Tree(10) As NodeData ' 10 branches on first level of tree
Set Tree(1) = New NodeData ' 1
Redim Tree(1).node(3) As Variant ' Dim for 3 branches on second
level
Set Tree(1).node(1) = New NodeData ' 1.1
Redim Tree(1).node(1).node(6) As Variant ' Dim for 6 branches on third
level of 1st branch
Tree(1).node(1).node(1) = "Some text for node 1.1.1"
Tree(1).node(1).node(2) = "Some text for node 1.1.2"
Tree(1).node(1).node(3) = "Some text for node 1.1.3"
Tree(1).node(1).node(4) = "Some text for node 1.1.4"
Tree(1).node(1).node(5) = "Some text for node 1.1.5"
Tree(1).node(1).node(6) = "Some text for node 1.1.6"
Set Tree(1).node(2) = New NodeData ' 1.2
Redim Tree(1).node(2).node(2) As Variant ' Dim for 2 branches on third
level of 2nd branch
Tree(1).node(2).node(1) = "Some text for node 1.2.1"
Tree(1).node(2).node(2) = "Some text for node 1.2.2"
Tree(1).node(3) = "Text for 1.3"
End Sub
As you can see, this is flexible and you can build as many nodes/levels
as you like.
Good luck!
/Karl
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
=============
Visit my blog at http://www.bleedyellow.com/blogs/texasswede/