Preserve
Used with ReDim to preserve contents will resizing an array
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.
NOTE: ReDim Preserve may not work as expected in all cases:
Syntax
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.
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.
Its behavior is only well-defined 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 multiple dimensions, only the upper bound of the first dimension may be changed safely. If lower-order dimensions are resized at all, the effects can be hard to predict.
Its behavior is only well-defined 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 multiple dimensions, only the upper bound of the first dimension may be changed safely. If lower-order dimensions are resized at all, the effects can be hard to predict.
Example
ReDim array(1 To 3) As Integer
Dim i As Integer
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
Dim i As Integer
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 wasn't supported until PDS 7.1
See also