Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need some help with the algorithm
Message
 
 
À
07/10/2010 13:45:45
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01484275
Message ID:
01484747
Vues:
69
>Sorry, my VFP is too rusty to just grok that without stepping it :-{
>
>>May be you can spot a problem in the SaveChild method:
>>
>>BTW, the first problem I see here - why did I declare iNodeIndex local if I pass it as a parameter - may be I introduced this bug.
>>
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform