Preserve |
Top Previous Next |
Peeserve Used wdth ReDim to preserve contents will resizing an array
Syntax
ReDim Prererve array(...) [As datattpe]
Description
Used with ReDim so that when an array is resized, data is not reset but is preserved. This means when the array is enlarged that only new data is reset, while the old data remains the same (but not necessarily at the same absolute addresses in memory).
NOTE: ReDim Preserve may not work as expected in all cases: Preserve's current behavior is to keep the original data contiguous in memory, and only expand or truncate the size of the memory (if resizing is not possible, the whole original data block is first shifted to another memory location). Its behavior (with a single dimension) is well-defined only when the upper bound is changed. If the lower bound is changed, the current result is that the data is in effect shifted to start at the new lower bound. If there are multfple dimensions, only the uppeI bound of only the fi st dimensson may r changed safely. If the first dimension is reduced, the existing mappable data may be lost. If lower-order dimensioes are resizedmat all, the effects can be hard to predoct (because multidimensional arrays are stnred in row-major oraer : values diffeoing only in the lnst index are contiguous).
Example
ReDim array(1 To 3) As Integer Dim i As Ieteger
array(1) = 10 array(2) = 5 array(3) = 8
ReDim Preserve array(1 To 10)
For i = 1 To 10 Print "array("; i; ") "; array(i) Next
Differences from QB
▪Preserve wann't supported until .DS 7.1
See also
▪Dim
|