Folks I need help. I have a view or(Text file) as follows:
'1
2.1
1.1.1
1.1.1.1
2.2.1
1.3
2
Dim Parent() As String
Dim Level1() As String
Dim Level2() As String
Dim Level3() As String
etc …
How can I construct a tree. parent, children, grand children etc…
and also figure out # of children # of grand children etc
Thanks
Subject: RE: Help construct a tree 1 → 1.1 → 1.2 → 2 → 2.1 → 2.1.1 etc HELP !!!
I don’t understand why you have a text file that contains some outline numbers and some LotusScript code. I think you are too close to the problem; you need to back off and explain in more general terms what you’re trying to do.
There are many ways to represent tree structures. If the elements of the tree are documents, you can do it with parent-response relationships and display the numbered outline in a view. If you’re creating text in a document, you can do it with indentation and putting the numbers into the text. If you’re managing structured information in memory, you could create a Tree class with a sibling link and a first-child link to other Tree elements.
So basically, we need more information about what you’re doing. If you’re not sure what information to supply, the C R I S P Y document might help you.
- Andre Guirard, IBM/Lotus Development
Useful blog: Best Practice Makes Perfect
Subject: RE: Help construct a tree 1 → 1.1 → 1.2 → 2 → 2.1 → 2.1.1 etc HELP !!!
Andre Guirard here is the problem:
I have a text file as follows: No documents just a plain text file
1
2.1
1.1.1
1.1.1.1
2.2.1
1.3
2
I want to construct a tree, a parent child grand child relationship
i.e read line 1 Uh huh that is a parent, next read Uh huh, that is a child
of a parent we have not yet known. add to an array and resize it appropriately
Below is code I have attempted
Const Parents = 10
Const Level1 = Parents
Const Level2 = level1
Const Level3 = level2
Dim NodeParent() As String '1
Dim NodeLevel1() As String '1.1
Dim NodeLevel2() As String '1.1.1
Dim NodeLevel3() As String '1.1.1.1
Redim NodeParent(1 To Parents)
Redim NodeLevel1( 1 To Parents, 1 To Level1 )
Redim NodeLevel2( 1 To Level2 )
Redim NodeLevel3( 1 To Level3 )
Do While Not ( ThisDoc Is Nothing )
For i = 1 To Level3
For ii = 1 To Level2
For iii = 1 To Level1
If ThisDoc.SCBS(0) Like "#" Then
NodeParent(iii) = ThisDoc.SCBS(0)
Elseif ThisDoc.SCBS(0) Like "#.#" Then
NodeLevel1(iii, ii) = ThisDoc.SCBS(0)
Elseif ThisDoc.SCBS(0) Like "#.#.#" Then
Elseif ThisDoc.SCBS(0) Like "#.#.#.#" Then
End If
Next
Next
Next
Set ThisDoc = ThisView.GetNextDocument( ThisDoc )
Loop
Subject: RE: Help construct a tree 1 → 1.1 → 1.2 → 2 → 2.1 → 2.1.1 etc HELP !!!
You will always be severely limited in your programming efforts if the only data structure you know is an array. This is not an appropriate application for arrays.
You say you’re processing a text file, but then you show us code that processes a collection of documents. Do you understand this code at all?
You have to actually think about each statement in your code and what it does – sorry, but there is no way to code without thinking. What are all those nested loops for?
I ask you again to back up a step and explain what you’re trying to do. Not “create a tree”. Why do you want a tree? What will you do with it once you have it? Pretend I’m an end-user who doesn’t know any LotusScript and explain what feature you’re working on.
Subject: RE: Help construct a tree 1 → 1.1 → 1.2 → 2 → 2.1 → 2.1.1 etc HELP !!!
Andre, I did explain it “AND” in EnglishRead a text file as follows:
1
1.1
3.1.1
3.2 etc…
and construct a tree. What I am trying to figure out are the children of each parent. And my programming efforts are not only arrays.
Andre, Keep coding simple
“Do you understand this code at all?” Yes!!!
Subject: RE: Help construct a tree 1 → 1.1 → 1.2 → 2 → 2.1 → 2.1.1 etc HELP !!!
OK you read Andres response, but we’re still none the wiser what you mean by a tree. What do you want an Activex Tree control? Do you just want Notes documents with a response hierarchy with the same numbers from @docnumber?
What is your end goal?
The simple answer to your problem is recursion. Which is probably as useful as saying you want a tree.
Is there a maximum document depth of 4 documents? Why not sort the text file before processing, that way you should not have an issue of documents like 2.1 being mentioned before 2 has been mentioned.
Will you have orphaned documents with no parents?
Will you have documents that are missing, like 1.2 is missing?
There is also a really really simple solution to your problem if you use a categorised view, and that is to replace . with \
Then they will be categorized together automatically by the view engine. But is this what you mean by a tree?
Subject: RE: Help construct a tree 1 → 1.1 → 1.2 → 2 → 2.1 → 2.1.1 etc HELP !!!
Ok I will try again:
I have a problem. I need to figure out a tree structure where
There is a General category a sub category and a sub sub category
Now these categories have an ID of 1 for category 1.1 for sub category etc…
They are not documents.They are from an excel file
The solution I am trying is to read a text file and construct a tree(much like nodes in XML)
Costruct an XML file like
<SubSubCategory1>
<SubSubSubCategory1>
<SubSubCategory2>
<SubSubSubCategory1>
<SubSubSubCategory2>
Now the above corresponds to
the following text file
Parent: Category1
Children: ,
Grand Children: , etc
The long Long Option would have been to import and create a view categorize it and read it
again. A much much cumbersome fix and a huuuuge performance hit.
XML I found out the hard way has unpredictable results with CATEGORIZED views
This solution will be a nightly agent that reads a 5pm
file with all 1, 1.1 2.2 etc and creates the tree the following morning
Thanks
Subject: RE: Help construct a tree 1 → 1.1 → 1.2 → 2 → 2.1 → 2.1.1 etc HELP !!!
So if I understand you correctly, you already know how to use data structures, you need to create a class to represent an outline tree, and you’re looking for someone to write the code for you for free?
I don’t know of such a thing already written, though if you search the internet for lotusscript class tree (or outline) you might find something.
Subject: RE: Help construct a tree 1 → 1.1 → 1.2 → 2 → 2.1 → 2.1.1 etc HELP !!!
Andre, that’s why I asked in this forum. I have searched and it is a lot easier to start from something. Look if you cannot SOLVE a problemdo not reply. I hate know it all who rudicule others
and offer nothing. And yes I can write it, I can solve it BUT I am looking for a better approach. This forum
is an exchange of ideas not a peacock pride show off!! Ok
Subject: RE: Help construct a tree 1 → 1.1 → 1.2 → 2 → 2.1 → 2.1.1 etc HELP !!!
Left padding, List, array of list tags, sort (Shell will do nicely). NotesDOMParser if you need an actual tree-type memory structure for analysis. That’s all the help you get after a response like that.