View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Why doesn't this function return TRUE?

Daniel,

Tried your function, but it doesn't work. It doesn't return TRUE when it
should.
I checked it with a Msgbox and it exits on the first node returning a FALSE,
no matter whether this node is ticked or not.
Although the recursive function may seem inefficient it passes every node
only once until the condition is met.
I would think that one could come up with a non-recursive function that
traverses the Treeview the way I described and I tried that at first, but is
not as easy as it seems. That is why I used the function in the book Tom
mentioned.
I am actually not sure you understand the problem. Forgive me if I am wrong.
The Treeview has to be traversed from top to bottom that is starting with
the root node and then nodes with increasing actual physical distance away
from the top of the screen.

RBS


"Daniel.M" wrote in message
...
Hi RBS,

It has to be a recursive function as in the code I gave as it is the

only
way I can be sure the Treeview is traversed from top to bottom as it

shows
on the screen.


One way. Not the only way :-)

AFAIK, in the pdf file (thanks Tom for the link), the recursive call is

just
a fancy (and inefficient) way of incrementing the level number (called
intDepth) appropriately so as to print it correctly with the Write cmd.

It's
a bad attempt of putting a preorder traversal algo on a 'serial'

collection
with added tests with children/parent (sorry to be so heavy).

That being said, why don't you start with your aNode, verify if it's

checked
and use the .Parent property to find if any of the parents (a simple loop,
jumping from parent to parent's parent to parent's parent's parent, etc
until the Root .) have their checkbox set or not.

I would do it this way:

Function CheckMissingTicks2(ByRef aNode As Node) As Boolean
Dim n As Node
Set n = aNode

Do While True
If n.Image = 9 Then ' don't bother except if at the root
If n.Checked = False Then ' you're missing one!
CheckMissingTicks2 = True
Exit Do
End If
End If
Set n = n.Parent
If n Is Nothing Then Exit Do ' at the root : exit
Loop
End Function


Again, I don't know what I'm talking about (never used that control

before)
;-)
However, I'm still interested in knowing (briefly) how this specific code
fails with respect to your specs.

Regards,

Daniel M.