Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Why doesn't this function return TRUE?

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




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

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





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why doesn't this function return TRUE?

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







  #4   Report Post  
Posted to microsoft.public.excel.programming
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








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why doesn't this function return TRUE?

I had the same two thoughts. I noted that the function never set the value
to false, but overlooked the fact that it implicitly returned false when a
true condition was not found, so it is as you state.

I haven't used a treeview either, and I noted as well the check about
parent - indicating that the loop was around all nodes, but did't know what
is in that collection, so I didn't raise that. If this routine came from my
suggestion as he indicated, I just provided a link to a book that provided
the code.

---- < my post with the link -----
See this link:

http://www.nuvisionmiami.com/books/vb6/files/ch03.pdf

go to section 3.4.3 on page 25 of 48.


------------------------

In Visual Basic Controls in a Nutshell - Evan s. Dictor, he says all items
are nodes and thus members of the nodes collection.

I didn't go back and check the above reference, but I suspect the recursive
approach is provided for traversing the structure of the control and as you
suggest, to just check all nodes for a condition, as RB is doing, a simple
loop through the collection of nodes would be sufficient.



--
Regards,
Tom Ogilvy



Daniel.M wrote in message
...
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












  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why doesn't this function return TRUE?

OK, but you still need to take action when that condition is found - because
a search on the next leg which does not have that condition would change the
value of the function to false and the original problem would be lost.

Regards,
Tom Ogilvy


RB Smissaert wrote in message
...
Tom, Daniel,

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.
For my application I have to check if there is a particular node (with a
particular image) not preceded (as showing on the screen) by a node with a
ticked checkbox. For example I can't traverse the Treeview by the indices

of
the nodes as they may not correspond with the order as shown on the

screen,
for example when nodes are added later, higher than the bottom node.
Haven't looked into the other point yet, that is not exiting the function
when the condition is met, and I will do this.
Thanks again for the assistance.

RBS


"Tom Ogilvy" wrote in message
...
I had the same two thoughts. I noted that the function never set the

value
to false, but overlooked the fact that it implicitly returned false when

a
true condition was not found, so it is as you state.

I haven't used a treeview either, and I noted as well the check about
parent - indicating that the loop was around all nodes, but did't know

what
is in that collection, so I didn't raise that. If this routine came

from
my
suggestion as he indicated, I just provided a link to a book that

provided
the code.

---- < my post with the link -----
See this link:

http://www.nuvisionmiami.com/books/vb6/files/ch03.pdf

go to section 3.4.3 on page 25 of 48.


------------------------

In Visual Basic Controls in a Nutshell - Evan s. Dictor, he says all

items
are nodes and thus members of the nodes collection.

I didn't go back and check the above reference, but I suspect the

recursive
approach is provided for traversing the structure of the control and as

you
suggest, to just check all nodes for a condition, as RB is doing, a

simple
loop through the collection of nodes would be sufficient.



--
Regards,
Tom Ogilvy



Daniel.M wrote in message
...
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













  #7   Report Post  
Posted to microsoft.public.excel.programming
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.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why doesn't this function return TRUE?

Your free to do whatever you want.

Regards,
Tom Ogilvy


RB Smissaert wrote in message
...
Tom, Daniel,

One thing I forgot to mention is that HasTick has to be declared at module
level, otherwise a TRUE won't be retained when doing a recursion.
About the other point. I don't think there is a difference between the 2
ways as indicated by option 1 and option 2:

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

Dim nodChild As Node
'HasTick has been declared at module level
'to retain the variable when doing a recursion

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

MsgBox "nodChild.Text: " & nodChild.Text & _
vbCrLf & _
"HasTick: " & HasTick

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

'option 1
CheckMissingTicks = _
CheckMissingTicks(nodChild, intDepth + 1)

'option 2
'If CheckMissingTicks(nodChild, intDepth + 1) Then
'CheckMissingTicks = True
'Exit Function
'End If

End If
End If
Next nodChild
End If

End Function


RBS



"Tom Ogilvy" wrote in message
...
I had the same two thoughts. I noted that the function never set the

value
to false, but overlooked the fact that it implicitly returned false when

a
true condition was not found, so it is as you state.

I haven't used a treeview either, and I noted as well the check about
parent - indicating that the loop was around all nodes, but did't know

what
is in that collection, so I didn't raise that. If this routine came

from
my
suggestion as he indicated, I just provided a link to a book that

provided
the code.

---- < my post with the link -----
See this link:

http://www.nuvisionmiami.com/books/vb6/files/ch03.pdf

go to section 3.4.3 on page 25 of 48.


------------------------

In Visual Basic Controls in a Nutshell - Evan s. Dictor, he says all

items
are nodes and thus members of the nodes collection.

I didn't go back and check the above reference, but I suspect the

recursive
approach is provided for traversing the structure of the control and as

you
suggest, to just check all nodes for a condition, as RB is doing, a

simple
loop through the collection of nodes would be sufficient.



--
Regards,
Tom Ogilvy



Daniel.M wrote in message
...
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













  #9   Report Post  
Posted to microsoft.public.excel.programming
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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to return a number instead of true/false with an if function? charles New Users to Excel 3 October 1st 09 07:50 AM
Search for 2 true arguments and return true or false David Excel Discussion (Misc queries) 3 July 15th 06 10:18 AM
How do I make the true return a drop down list in the IF function? Brian Excel Worksheet Functions 5 April 13th 06 09:40 PM
Function to return True/False if all are validated as True by ISNU Tetsuya Oguma Excel Worksheet Functions 2 March 15th 06 10:28 AM
Create a function to return text if two logical functions are true janeyt Excel Worksheet Functions 2 March 19th 05 08:49 PM


All times are GMT +1. The time now is 09:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"