Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Where is my logic this morning?
Message
From
22/10/2003 09:34:46
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Where is my logic this morning?
Miscellaneous
Thread ID:
00841000
Message ID:
00841000
Views:
44
I'm trying to step through a table to populate a treeview and I can't seem to get my 'head around it' this am. :o(

My table's records looks like this:
* All parent values of A0 are top level branches - any self value of
* nothing in spaces 5 and 6 or the value of B1 in spaces 5 and 6 are top level.
* All other values in spaces 5 and 6 are sub levels and fall under the branch
* of its parent

cPARENT        cSELF           SEQ           

A0             1MHG                    && top level message header
A0             2TRG            1829    && top level 1st transaction
A0             5BISB10001      1829    && top level
A0             9BISB10001      1829    && top level
5BISB10001     5BPIF10001      1829    && 2nd level branch, directly under 5BISB10001
5BPIF10001     5DRVF20001      1829    && 3rd level branch, directly under 5BPIF10001
5BPIF10001     5DRVF20002      1829    && 3rd level branch, directly under 5BPIF10001
5DRVF20001     6PDRF30001      1829    && 4th level branch, directly under 5DRVF20001
A0             2TRG            1830    && top level 2nd transaction
A0             5BISB10001      1830    && top level
A0             9BISB10001      1830    && top level
5BISB10001     5BPIF10001      1830    && 2nd level branch, directly under 5BISB10001
5BPIF10001     5DRVF20001      1830    && 3rd level branch, directly under 5BPIF10001
5BPIF10001     5DRVF20002      1830    && 3rd level branch, directly under 5BPIF10001
5DRVF20001     6PDRF30001      1830    && 4th level branch, directly under 5DRVF20001
5DRVF20001     6PDRF30002      1830    && 4th level branch, directly under 5DRVF20001

Note: 1st four characters are type i.e. 5BPI, 5BIS, 1MHG, etc.
      5&6 are 'sortof' levels i.e. B1, F1, F2, etc
      7-10 is a counter that denotes it is the first, 2nd, etc 0001, 0002, etc.
      Records are stored in this order and each 2TRG record denotes the
      next 'group' or transaction

The records should look like this in the treeview:

1MHG                         && 1st Message
2TRG                         && 1st transaction or 'group' in this message
5BISB10001
    5BPIF10001               && 1st 5BPI under this 5BIS in 1st transactioin
        5DRVF20001           && 1st 5DRV under this 5BPI
        5DRVF20002           && 2nd 5DRV under this 5BPI
            6PDRF30001       && 1st 6PDR under this 5DRV
9BISB10001
2TRG                         && 2nd transaction or 'group' in this message
5BISB10001
    5BPIF10001               && 1st 5BPI under this 5BIS in 2nd transaction
        5DRVF20001           && 1st 5DRV under this 5BPI in 2nd transaction
        5DRVF20002           && 2nd 5DRV under this 5BPI in 2nd transaction
            6PDRF30001       && 1st 6PDR under this 5DRV in 2nd transaction
            6PDRF30002       && 2nd 6PDR under this 5DRV in 2nd transaction
9BISB10001
All of the records in the treeview are in the table 'al3parnt' and the fields are cparent, cself, seq, ckey (quid key), etc...

When the form's init is run I call the form's method addrecds which should populate the tree. I step through the table (tried it different ways) and try to populate the treeview appropriately.

Here is my latest effort (a poor one at that):

* The only way I seem to be able to determine which node to put the child under (reference it) is with the node.text value so far:
SELE Al3Parnt
set ORDER to 0
GO TOP
SCAN
	STORE RECNO('al3parnt') TO mrecno
	* al3parnt.cparent is the parent of this record or upper branch
	* al3parnt.cself is the identity of this record
	STORE al3parnt.seq TO mseq          &&  transaction sequence number
	IF al3parnt.cparent = "A0"          &&  this record's parent 'branch' A0 is always top level branch
		tNode = THISFORM.AddNode(oNode) &&  add this top level node
		tNode.Text = al3parnt.cSELF     &&  this record's identity
		tNode.Expanded = .T.
		tNode.Image = 1*5 + 1
		mtext = tNode.Text
		* Now create the child branches for this top level branch
		* based on the records' cparent field matching this record's cself field
		SCAN FOR ALLTRIM(UPPER(al3parnt.cparent)) = ALLTRIM(UPPER(mtext)) .and. al3parnt.seq=mseq
			xNode = THISFORM.AddNode(tNode)  && add the child branch to the above parent branch
			xNode.Text = al3parnt.cSELF       && this child branch's identity
			xNode.Expanded = .T.
			xNode.Image = 1*5 + 1
			mtext = xNode.Text
			*!* Here is where I get stuck
			* Now need to process this child record's sub branches if any, but my
			* logic is wrong because this obviously won't work.  I need to determine 
			* how many levels it could possibly go or handle an infinite number of 
			* sublevels (child branches)
		ENDSCAN
	ENDIF
	IF RECNO()<>mrecno
		GOTO mrecno
	ENDIF
ENDSCAN
Thanks to anyone willing to look at this! I get everything fine through the 2nd level only obviously...
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Next
Reply
Map
View

Click here to load this message in the networking platform