View Single Post
  #4   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?

Tom, RBS,

Agreed.

More than that, it will continue and potentialy find other Nodes (in the For
Each) for which the call to CheckMissingTicks=CheckMissingTicks(nodChild,
intDepth +1) will return False, thus overwriting a True previously found.
So, apart of the speed issue, I think you SHOULD exit.

That being said, the key issue here is in understanding :
"It should return TRUE if a particular node is found (with a particular
image) and no ticks have been found yet."

What the 'yet' means? What is the ORDER (pre-order, post-order) of the tree
traversal?

I've never used the Treeview control (so beware! ;-)) but I don't understand
why you would do an all nodes search "For each" loop (recall that ALL the
nodes, not level by level, are counted with the current "For each") and then
include a recursive call in it.

I'm sure there is a way to optimize this search if the OP explains what he
means by 'no ticks have been found yet'. If this is what I think, the OP
doesn't need the recursive call at all.

Regards,

Daniel M.

"Tom Ogilvy" wrote in message
...
It may be shorter to write, but it doesn't exit your function as soon as a
True condition is encountered so you could continue to loop and do

needless
checks - thus shorter to write, longer to execute.

Regards,
Tom Ogilvy




RB Smissaert wrote in message
...
Thanks, it works fine now.
Used Daniel's suggestion as it is a bit shorter.
Wasn't sure about the Call keyword, but it was used in the example I
mentioned.

RBS


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

For one thing:

Instead of
Call CheckMissingTicks(nodChild, intDepth + 1)
put
CheckMissingTicks=CheckMissingTicks(nodChild,

intDepth
+
1)

Don't know if it solves all your problems.

Regards,

Daniel M.

"RB Smissaert" wrote in message
...
Using Excel XP.
Made a function (from an example pointed out by Tom Ogilvy) that

checks
for
missing ticked checkboxes in a Treeview.
It should return TRUE if a particular node is found (with a

particular
image) and no ticks have been found yet.
The function does work when I check it with a messagebox, but it

still
returns FALSE when it should be TRUE.
This is the function:

Function CheckMissingTicks(ByRef nodCurrent As Node, _
ByVal intDepth As Integer) As Boolean

Dim nodChild As Node
Dim HasTick As Boolean

If nodCurrent.Children 0 Then
For Each nodChild In MainForm.TreeView1.Nodes
If Not nodChild.Parent Is Nothing Then
If nodChild.Parent Is nodCurrent Then

If nodChild.Checked = True And _
Not nodChild.Image = 9 Then
HasTick = True
End If

If HasTick = False And _
nodChild.Image = 9 Then
'collection node, but no tick found yet
CheckMissingTicks = True
Exit Function
End If

Call CheckMissingTicks(nodChild, intDepth + 1)
End If
End If
Next nodChild
End If

End Function


And this is how the function is called:

If CheckMissingTicks(TreeView1.Nodes(1), 0) = True Then

..............


I solved it for now by declaring a variable that will be true if the
particular conditions are met and checking for this variable, but I

am
just
puzzled by what is wrong here. Most likely I am overlooking

something
really
simple and somebody could help me out easily.


RBS