View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default strange problem For Each loop in Treeview

Peter,

Just tried your code on a tree with a structure as you gave in your code and
on that tree it works fine.
So it seems it doesn't work with me as I used a different tree.
It seems therefor that your code needs altering somehow.

RBS


"Peter Beach" wrote in message
...
Hi,

Odd. My code worked fine for me.

The point I was making was that I can't see the purpose of the lines:

For Each nodChild in MainForm.TreeView1.Nodes
If Not nodChild.Parent Is Nothing Then
If nodChild.Parent = nodcurrent Then

which would seem to iterate through the tree until the target node is
reached. But you already know what the target node is - it's either the
first node (for the initial call) or the it's the node currently being
inspected, so it seems to me that you don't need to go iterating through

the
tree looking for it. You can from the node recursively call the routine

for
the first child and then iterate through all its siblings.

However programming is that art of achieving results, if your code works,
stick with it.

Regards,

Peter Beach

"RB Smissaert" wrote in message
...
Peter,

Given your code a try, but it doesn't work.
UBound(sItems) gives 67000, which I presume is the limit of what the

array
can hold and it gets into an endless loop.
The code I use now is actually very efficient as it passes every node

only
once. Have you tried both ways?

RBS


"Peter Beach" wrote in message
...
Hi,

Glad you got it worked out. I'm still a bit puzzled by your code, as

you
seem to iterate through the entire tree each time, searching for your

target
node whereas it is surely more efficient simply to work down and

across
from
the target node. The code I posted earlier only traverses the tree a

single
time which would seem to be more efficient.

Regards,

Peter Beach

"RB Smissaert" wrote in message
...
Peter,

The Sub is fine. It was just the typo as stated in my previous post.

RBS