Hi David: What you are looking at in that little sub is called a recursive 
routine.
A recursive routine will call itself if a specified condition is met.
They are very useful for processing anything that uses nodes like a TreeView or 
xml document or even a form menu.
I wont get into much more since I havent done much with vbs and dont want to 
confuse you but if you do a little introductory reading about recursive 
routines you will see how powerful they can be.
As for your tree view, 9 levels is way too many if you are going to use it for 
real.
It requires too much guessing and expanding and collapsing and liniar 
navigation compared to other solutions to handle that many choices.
It also will be a pain to work with that many levels if just learning.
Anyway, I'll begg of for nnow since vb.net TreeViews may have diferent methods 
and properties although they sound pretty much the same.
600 lines of code is a whole lot of code to muck with a TreeView but when you 
start working with indexes and check boxes I guess it could get that large.
Rick USA
  ----- Original Message ----- 
  From: David 
  To: [email protected] 
  Sent: Thursday, April 11, 2013 9:12 PM
  Subject: Re: Treeview Questions - Still attempting to learn :)


  Yes, Bruce.
  I do follow you somehow here. If you have a simple tree, holding three 
levels, with a maximum of 10 entries on each level, you could do your kind of 
math. The number 175, then would indicate, we are to follow the first branch 
from the root, the seventh branch of the next level, and finally, get hold of 
the fifth leaf (or item) on the third level. 

  Now, if we imagined that the three items here in question, had the respective 
names of "Grocery", "Lunch meat", and "Ham". Allright, you could follow 
numbers, calculated from the Data field, and I do see that could be easy. But 
you also could run through the levels, and follow the text strings: Grocery, 
lunch meat, Ham. Again, this will take, that there never occurs same text, on 
more than one item.

  But another issue, that comes from your Data field math, is this. Now, 
imagine that you have five levels, and you reserve enough space in your 
calculation for having one hundred entries as a max on each level. You then 
would have the numbers: 10, 89, 22,11,75; which you would have to put together 
for an entry in the Data field. It all would come out, as the tremmendous 
number of: 1089221175. Still, the number would fit inside the maximum of a 
LongValued number. But hang on, we are going to elaborate just a bit more. As I 
told, my tree will at the max have ten levels. If now, we are to reserve space 
in our calculation of the Data field, for a maximum of one hundred entries on 
each level, you would end up with a 20 digit number for the Data field. This 
will (I guess), by far exceed the limits of any handled numbers on the 
computer. As such, I guess the Data field will no longer have any benefit, as I 
would have to store it as a String, and perform a split of that string into 
separate two-digit numbers, for refering to the branch of each level to follow. 
My big issue here, is if all that calculation and splitting of numbers, 
actually will result in just as much coding and computer resources, as would 
the tracing of the Text field that matches a specified criteria. Hope this all 
made sense. I am not telling the one approach to be superior to the other, only 
was wondering if there was any direct features for the Data field build in with 
the treeview object, that would not be available on the Text field. I.e, it 
would have been nice, if you could have entered one instruction, passing the 
Data field to the object, and it would have returned the full Tree-lim, if you 
know what I mean. But my guess is, there is none such feature, and so the one 
approach might do fine - and the other will do just as well. OK, one might be 
more in line with high-tech and professional ways of handling the matter, the 
other might be a bit more homemade. :) At least, that is what I get from it 
all, at this point. 

  Again, if you have other stuff, which you need to compare with a selection 
from the treestructure, I can see it might be nice with a number retrieved in 
the background from the Data field - which you in turn could use for looking up 
things in a database or a dictionary. I just wonder, how you would approach a 
twenty digit number in the Data field. My guess is, that you would have an 
error thrown at you, if you tried to assign such a number to the Data field. 
Nope, I haven't tried, but was just making a guess here.

  Still, thank you for trying to clarify, and I do appreciate any further 
feedback.


    ----- Original Message ----- 
    From: BX 
    To: [email protected] 
    Sent: Friday, April 12, 2013 1:49 AM
    Subject: Re: Treeview Questions - Still attempting to learn :)


    Hi David,

        The text in the tree view is the stuff you see being said on the tree. 
The data, is the ID tag for that item selected.
        Now, when you go down another level, you deciding the data to reflect 
the level.
        Suppose you have on the main list 10 items, OK?
        Then on the second level you have no more than 10 items, OK?
        The the third level you also have 10 items, OK?
        Now you are dealing with powers of 10, or 0 to 9. So, you have 3 levels 
so each ID tag of each level would be a power of 10, or if your selected item 
is 19, OK?
        Then you are item 1 of the first level and the 9'th, actually 10'th 
item of the second level, OK?

        This is how you set your check box, which does not exist, but the tree 
view, or limb you follow is the value of the data item at that point.

        This is what I had sent you and yes, what I sent you is confusing, but 
the guts of that is the beginning of the MainProc where I start doing that 
level check; but you have to understand my program to get there.

        so, as I have mentioned above, set your data value to show the full  
amount of data, checks at the tree view level you are opened up to.

        In this case you only have one item selected at each level and that is 
all you can do in a tree view, but since you are selecting a sub value of a 
main level, you do not need anything more than that. For that is the meaning of 
a tree view, following a tree limb...


        I hope this helps. I will send or post the tree view items and how to 
make them, there are only 2 or 3 places where that happen, one place where the 
main menu is made into categories, then the listing of file names or 
programming names in the second level, and the third level is the info supplied 
for each program. This is what I did in the UnInstall program.

        So, the text is what is displayed and said when you move through the 
tree view, the data is the ID tag for each and every item on the tree and you 
make up the rules for that.
        As I said, using the power of 10 only allows 10 items for each sub 
level. You can expand that as I did to indicate up to a 1000 at each level 
which means you are going down each level as a power of 3 each. You can make it 
even large, each call to the subroutine must reflect that choice.
        But ID tags can be words as well if you choose to do so...

        I hope this helps, next I will send the exact 2 programs that do this 
for you, along with the controlling top level loop...

            Sincerely
            Bruce A. Babcock



      Sent: Thursday, April 11, 2013 7:18 PM
      Subject: Re: Treeview Questions - Still attempting to learn :)


      As regards to my prior message, I have solved issue number 3, how to 
quickly iterate
      the whole tree-structure. Still, my other questions remain open.
      But for what it is worth, and to all who might benefit from a quick way 
of running
      through all the possible items on a tree, here I am pasting in the sub 
routine, that
      will do the whole iteration. It is not more than a few lines of coding, 
and will
      do with any number of branches and leaves, from what I can see. In the 
pasted example,
      the actual line of interest, is the Speak line, which will read out the 
Text property
      of the individual item. You can replace this line, with any other 
activity you want
      performed on the individual item. The sub will take a TreeviewItems 
object, as its
      parameter. If you want the whole treeview iterated, from root and out, 
you could
      simply do something like:
          IterateTree TreeviewObject.TopLevel
      Where TreeviewObject is an object pointing to a treeview, that you have 
defined.
      In my testing app, I called it from the DialogEventHandler function of my 
testing
      dialog. Here I have defined a treview control, named TV_Test, and the sub 
is called
      when a button "BTN_SpeakTree) is pressed. The snip-it of the 
DialogEventHandler then
      looks like this:
          Case "BTN_SpeakTree"
              If DEvent = ButtonClicked Then
                  IterateTree DObj.Control( "TV_Test" ).TopLevel
                  DialogEventHandler = True
                  Exit Function
              End If 'BTN_SpeakTree.
      And, here is the iteration sub:
      Sub IterateTree( TVItems)
       Dim CurrentItem: Set CurrentItem = Nothing
       Dim ItemNumber
       For ItemNumber = 1 To TVItems.Count
        Set CurrentItem = TVItems.Item( ItemNumber)
      ' The following line, is the actual action, performed on the individual 
item. Replace
      it with whatever you want:
        Speak CurrentItem.Text  &","
        If CurrentItem.Children.Count >=1 Then
         IterateTree CurrentItem.Children
         Set currentItem = Nothing
        End If 'CurrentItem.Children.Count >=1.
       Next 'ItemNumber.
      ' Room Cleaning:
       If Not CurrentItem Is Nothing Then Set CurrentItem = Nothing
       If Not TVItems Is Nothing Then Set TVItems = Nothing
      End Sub 'IterateTree.
      Hope all of this will be of any help for the rest of the community. I am 
sure, things
      can be modified to work even more smoothly, and that you can change 
whatever part
      of it, to fit your personal scripting needs. But at least, I wanted to 
share this,
      since it is not something that first comes to mind, how to handle. Enjoy 
it. And
      if anyone has any feedback on the other issues I presented in the initial 
message
      of mine, I am all greatful for whatever feedback you may have.
      Thanks again,
      ----- Original Message -----
      From:
      David
      To:
      [email protected]
      Sent: Thursday, April 11, 2013 11:14 PM
      Subject: Treeview Questions - Still attempting to learn :)
      I am still trying to wrap my brain around the complexity of a treeview, 
and how to
      gain the fullest benefit from this kind of control. Earlier, when asking, 
one of
      you send me a code snip-it from one of his apps, holding some 600 lines. 
Thanks to
      you, and it got me somehow going. Yet, I don't follow all of your 
thinking, or the
      reason why you do this and that. That is one of the drawbacks of 600 
lines of coding.
      Smile.
      Allright, I have got that far, that I am able to fill in the information 
on the tree,
      and get it displayed in my dialog. So far, this works satisfactory. Now, 
I am stuck
      with a few challenges, most of all when comes to retrieve the needed 
information
      from the treeview. I have a feeling, most of my getting stuck here, is 
due to a lack
      of understanding. That's why, I hoped to have some clarification on the 
following
      questions.
      1. What is the exact benefit of the Text, as compared to the Data, field 
in a treeview
      item. OK, I do get the fact, that in case the same text could happen to 
be on several
      branches or leaves of the tree, the Data field could be used to 
distinguish the one
      occurrance from the other. But if i have a tree, where no text will 
appear more than
      once, is there any reason why I should bother about filling in the data 
field for
      each item? I.e, would there be any search feature or the like, that could 
be quicker
      done by iterating the tree-structure on the Data fields, compared to 
simply just
      concentrating on the Text fields.
      2. The treeview I am building, has checkboxes, which the user can check 
for each
      item on the tree. I have searched the Reference manual, but not sure if I 
have overlooked
      anything. From what I can see, there is no way in determining whether a 
treeview
      Item has been checked or not. I see the Selected feature, but from what 
my testing
      leads me to understand, this simply let's me know when an item has focus 
(that is,
      when the cursor is placed on the item, the Selected feature will be set). 
Is it correct,
      that there is no build-in feature, that would "fire", when a treeview 
item has been
      checked or unchecked? If this is the case, technically, why? We have 
features for
      Checkboxes, which will tell us when it is checked and not - and we have 
similar features
      for a multi-selection listbox. Why would there be no feature set, 
whenever a treeview
      item is checked?
      3. Does anyone have a simple quick iteration routine, for "rushing" 
through a whole
      treeview, including all its branches and leaves. My treeview, might hold 
as much
      as 9 sublevels, in addition to the root. And it might hold different 
amounts of entries
      on each branch or sublevel. I guess the best would be to use some 
For...Next loops,
      and somehow retrieve the Count property for each branch. But I have run 
my head into
      the wall, as to how to get through absolutely all the possible items on 
the tree.
      I guess, that is the one way to go, when iterating the different items, 
or am I totally
      lost in such an approach? Say for instance, the user would have been 
given the chance
      of searching for a given text, which would be the Text property of an 
item on the
      tree. I then guess, I will have to iterate all the current items on the 
tree, looking
      out for that particular text. And, that is why, I wondered if there was a 
simple
      routine, that would perform such a "run-through", with relatively few 
lines of coding.
      Yep, I did read through I don't know how many pages, in the Reference 
manual, and
      I have been looking through quite a few lines of existing coding. I am 
sure, I can
      get on with this, if only I can wrap myself around a few corners. So, 
anyone who
      has the urge to help me on getting those pieces of information 
straightend out, thanks
      to you, as it surely will help me crawling my way further on. :) Only 
hope my questions
      were clearly enough stated, that you will be able to give me the right 
push. :)

Reply via email to