Jump to content

Recommended Posts

Posted

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. 

Posted (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 by czardas
Posted (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 by czardas

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...