Jump to content
Sign in to follow this  
billshu

UBound()

Recommended Posts

billshu

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. 

Share this post


Link to post
Share on other sites
czardas

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

Share this post


Link to post
Share on other sites
billshu

 

?

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

Share this post


Link to post
Share on other sites
czardas

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

Share this post


Link to post
Share on other sites
corgano

 

?

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

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×