Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need some help with the algorithm
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01484275
Message ID:
01484871
Views:
52
Unfortunately, I can not turn this into for each loop. If I try to access oTree.tList.Children collection, the returned object is not the same as oTree.Nodes objects and so I can not use them. I could not figure a connection between oTree.TList.Node and oTree.Node

Can you spot a problem in the current implementation?

>Hi Viv, Hugo,
>
>I added more logging and slightly changed the code - may be the problem will be more transparent now? I'm thinking to try to change this code to use Children as collection and so use for each loop instead of counter based loop - may be it should help?
>
>Any suggestions about the current code before I'll try to change it?
>
>
>LPARAMETER iNodeIndex
>LOCAL i, iTempIndex, nChanges, lnLast_Mod, lnSeekVal, oTree, loNode, oParent, lnChildren
>
>with Thisform
>  nChanges   = 0
>  oTree      = .TList2
>  oParent = oTree.Nodes(m.iNodeIndex)
>  iTempIndex = m.oParent.Child.FirstSibling.Index
>   .Log("Starting from: " + Descrip, PROGRAM(),1) 
>  lnChildren = m.oParent.Children && Total number of children
>  i = 1
>  *Loop through all Parent's Child Nodes
>   
>  FOR  i = 1 to m.lnChildren
>
>      loNode = oTree.Nodes(m.iTempIndex)
>      *lnSeekVal = val(substr(oTree.Nodes(m.iTempIndex).Key, 3))
>      lnSeekVal = val(substr(m.loNode.Key, 3))
>      IF SEEK(m.lnSeekVal,'ItemTree','Node_Id')
>         if sort_order <> m.i
>            .Log("Re-ordering: " + m.loNode.Key + ;
>                 ' for parent ' + m.oParent.Key, program(), 1)
>             .Log("Re-ordering item: " + Descrip, PROGRAM(),1)      
>            replace sort_order with m.i && re-orders
>            nChanges = m.nChanges + 1
>            .lUpdateItemTree = .T.
>         endif
>      else
>         .Log("Seek failed on node id:" + m.loNode.Key, program(), 1)
>      endif
>      * If the Node we are on has children, call the Sub again
>  	IF loNode.Children > 0
>  		nChanges = m.nChanges + .SaveChild(m.loNode.Index)
>  	ENDIF
>*!*	      * If we are not on the last child move to the next child Node
>  	IF  m.i <> m.lnChildren
>  		iTempIndex = oTree.Nodes(m.iTempIndex).Next.Index
>  	ENDIF
>     
>  ENDFOR
>
>ENDWITH
>
>return m.nChanges
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform