For Next Question

  • Thread starter Andrew Durstewitz
  • Start date
A

Andrew Durstewitz

Hi!

Does the uBound(array) update for the For/Next when updating it inside
the loop? Example:

For i = 0 To uBound(myArray) Step 1
Redim Preserve myArray(uBound(myArray)+1)
Next

Is the uBound(myArray) updated, or is it kept the same at the entrace
value?

Tnx,
Andrew

* * * Sent via DevBuilder http://www.devbuilder.org * * *
Developer Resources for High End Developers.
 
R

Ray at

Did you try and see? And are you /trying/ to create an endless loop? [:

Here's a test (.vbs):

myArray = Array("a","b")

msgbox "The ubound of the array before for-nexting is " & UBound(myArray)
For i = 0 To uBound(myArray) Step 1
Redim Preserve myArray(uBound(myArray)+1)
Msgbox "While in the loop with i being " & i & ", the ubound is " &
UBound(myArray)
Next
Msgbox "And now it is " & UBound(myArray)

Ray at work
 
A

Andrew Durstewitz

Ray,

It seems to work but I wanted to double check since the entire script is
so large.

No, I'm not trying to create an endless loop. The loop I gave you is
endless but just an example. What I am doing in inheriting permissions
from one person to another. Therefore I have to make sure the
permissions that I am inheriting aren't allready in my permissions
array. Basically analyzing 2 arrays.

Thanks for the info.
Andrew

* * * Sent via DevBuilder http://www.devbuilder.org * * *
Developer Resources for High End Developers.
 
P

Phill. W

.. . .
Does the uBound(array) update for the For/Next when updating it inside
the loop? Example:

For i = 0 To uBound(myArray) Step 1
Redim Preserve myArray(uBound(myArray)+1)
Next

No.
the parts of the For statement are only evaluated once, when the
loop is entered. Try using a While loopinstead.

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,097
Latest member
RayE496148
Top