billshu Posted August 17, 2014 Share Posted August 17, 2014 I have this code to process Array elements 2 thru N For $i = 2 to (UBound($TablePID) - 1) ProcessQueueChild( ($i) ) Next The problem is that one of the functions of ProcessQueueChild() is to ADD, Delete or Modify entries from the table $TablePID. I get arry index out of range errors when ProcessQueueChild() deletes a $TablePID element. I replaced this with the following code: $LocalQueue = 2 If (UBound($TablePID) > 2) Then Do ProcessQueueChild($LocalQueue) $LocalQueue = $LocalQueue + 1 until ($LocalQueue > (UBound($TablePID)-1) ) Else $TMMyString = "No Child Queues to Process " FileWrite($hFileOpen, $TMMyString & @CRLF) EndIf This seems to work so far, but is there a cleaner way to process this loop. Link to comment Share on other sites More sharing options...
czardas Posted August 17, 2014 Share Posted August 17, 2014 (edited) Something like this perhaps? Note - none of the variables have been declared in the posted examples. ; $iBound = UBound($TablePID) If $iBound > 2 Then For $LocalQueue = 2 To $iBound -1 ProcessQueueChild($LocalQueue) Next Else $TMMyString = "No Child Queues to Process " FileWrite($hFileOpen, $TMMyString & @CRLF) EndIf Edited August 17, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
mikell Posted August 17, 2014 Share Posted August 17, 2014 ? For $i = UBound($TablePID)-1 to 2 step -1 ProcessQueueChild($i) Next Link to comment Share on other sites More sharing options...
billshu Posted August 17, 2014 Author Share Posted August 17, 2014 ? For $i = UBound($TablePID)-1 to 2 step -1 ProcessQueueChild($i) Next Great, I knew there was a cleaner way. I had not consider processing in reverse order, but I see that is perfect. Thanks for you help Link to comment Share on other sites More sharing options...
czardas Posted August 17, 2014 Share Posted August 17, 2014 (edited) It's impossible to determine the best solution without seeing the function ProcessQueueChild. Also it's cleaner to only call Ubound once. Edit Hmm, I didn't read the first part of the question properly - sorry. I just recoded the example that was meant to be working. You really should have told me that the solution I posted wasn't working, then I would have looked more closely. Even if my understanding was at fault - it's only polite if someone tries to help you. Edited August 17, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
corgano Posted August 18, 2014 Share Posted August 18, 2014 ? For $i = UBound($TablePID)-1 to 2 step -1 ProcessQueueChild($i) Next Simpler than what I was thinking of For $i = 2 to 2^30 If $i > (UBound($TablePID) - 1) then exitloop ProcessQueueChild( ($i) ) Next Lol 0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now