how to redeclare an array with different size but keep the previous data?

  • Thread starter Thread starter Tee
  • Start date Start date
T

Tee

Hi,

Anyone know how to redeclare an array with different size but keep the
previous data? Just like the redim preserve in VB.


Thanks.
 
Tee said:
Hi,

Anyone know how to redeclare an array with different size but keep the
previous data? Just like the redim preserve in VB.

Just create a new array and copy the contents of the old array to it. I
believe thats basically all that ReDim does anyway.
 
Tee said:
If the redim is needed in a while loop, how should I do it?

In exactly the same way. However, you can make things faster by only
reallocating size in chunks - for instance, doubling the size of array
each time, and then reallocating it once after the loop to the "right"
size.
 
Back
Top