View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Daniel.M[_2_] Daniel.M[_2_] is offline
external usenet poster
 
Posts: 5
Default Why doesn't this function return TRUE?

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.