limiting depth of recursive function

SunWuKung

Registered User.
Local time
Today, 06:52
Joined
Jun 21, 2001
Messages
172
I have a very simple recursive function below, which seems to work well.
I would like to be able to specify how deeply the recursion can go - how many levels to refresh, but though I spent a long-long time trying am still unable to find a way to do it.

Thanks for your help in advance.
SWK


Private Sub RefreshNode(nodp As Node)
Dim objTree As TreeView
Dim nodX As Node

Set nodX = nodp.Child
Do Until nodX Is Nothing

ClearChildren nodX
AddChildNodes nodX

RefreshNode nodX
Set nodX = nodX.Next
Loop


End Sub
 
SunWuKung,

I don't use TreeView, but ...

This will terminate at level 8, but you could make
MaxDepth as a parameter too.

Code:
Private Sub RefreshNode(nodp As Node, Depth As Integer)
Dim objTree As TreeView
Dim nodX As Node

If Depth = 8 Then
   Exit Sub
End If

Set nodX = nodp.Child
Do Until nodX Is Nothing
  ClearChildren nodX
  AddChildNodes nodX
  RefreshNode(nodX, Depth + 1)
  Set nodX = nodX.Next 
  Loop

End Sub

Wayne
 
Wow Wayne,

this was great, worked perfectly.
I could have spent an other lifetime figuring it out.

Many thanks.
SWK


P.S
remove brackets from - RefreshNode(nodX, Depth + 1)
 

Users who are viewing this thread

Back
Top Bottom