Sub DoSomething(ByVal ID as Integer, ByVal Level as Integer)

    Dim ChildIDs() as Integer = GetChildIDs(ID)
    'Print out the current node
    Response.Write(String.Format("L:{0} ID:{1}", Level, ID))
    Dim i as Integer
    For i = 0 to ChildIDs.Length - 1
         DoSomething(ChildID(i), Level + 1)
    Next
End Sub

This is recursion.  Call the method with initial values for the parent
node and watch her rip.  If a node doesn't have children, it returns
control to calling version of the function, otherwise it calls itself
once for each child.

The getChildIDs function simply returns an array of IDs for children
of the supplied parent.

On 9/29/05, Mike Appenzellar <[EMAIL PROTECTED]> wrote:
> That is exactly how my table is setup, but I dont' really see how to
> implement it with the loops, etc. The link you sent unforuntately doens't
> tell me much.
>
> On 9/29/05, Dean Fiala <[EMAIL PROTECTED]> wrote:
> >
> > Simple form, infinite levels. All you need are three columns
> >
> > ID
> > Parent ID
> > Desc
> >
> > ID Parent ID Desc
> > -----------------------------------
> > 1 -1 Root
> > 2 1 First Child
> > 3 1 Second Child
> > 4 3 Grandchild A
> > 5 3 Grandchild B
> > etc...
> >
> > You can walk the hierarchy in either direction.
> >
> > Check out tree walking, recursive trees, etc. For example,
> >
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvbadev/html/traversingtreewalkingcode.asp
> >
> >
> > On 9/29/05, Charles Carroll <[EMAIL PROTECTED]> wrote:
> > > Recursion. Research it.
> > >
> > > On 9/29/05, Mike Appenzellar <[EMAIL PROTECTED]> wrote:
> > > >
> > > > I have a database structure setup as follows:
> > > > ID NAME PID
> > > > 1 Level1 0
> > > > 2 Level2 0
> > > > 3 Level3 0
> > > > 4 SubLevel1 1
> > > > 5 SubLevel2 2
> > > > 6. SubSub1 4
> > > > and so on...
> > > > Right now I have nested loops that take care of this BUT the problem
> > is
> > > > that I have to pre-plan on how many potential levels there might be. I
> > > > would
> > > > like to somehow right my queries or loops to plan for an unlimitied
> > amount
> > > > of levels.....any ideas?
> > >
> > >
> > > [Non-text portions of this message have been removed]
> > >
> > >
> > >
> > >
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> > --
> > Dean Fiala
> > Very Practical Software, Inc
> > http://www.vpsw.com
> >
> >  ------------------------------
> > YAHOO! GROUPS LINKS
> >
> >
> >    - Visit your group 
> > "AspNetAnyQuestionIsOk<http://groups.yahoo.com/group/AspNetAnyQuestionIsOk>"
> >    on the web.
> >     - To unsubscribe from this group, send an email to:
> >    [EMAIL PROTECTED]<[EMAIL PROTECTED]>
> >     - Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> >    Service <http://docs.yahoo.com/info/terms/>.
> >
> >
> >  ------------------------------
> >
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>


--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to