Uses "Console"
Long nNumbers(3)
nNumbers(1) = 1, 2, 3
PrintL "Original:"
PrintL Join$(nNumbers, ", ")
PrintL "After REDIM to 1 element:"
ReDim nNumbers(1)
PrintL Join$(nNumbers, ", ")
PrintL
PrintL "Original:"
ReDim nNumbers(3)
nNumbers(1) = 1, 2, 3
PrintL Join$(nNumbers, ", ")
PrintL "After REDIM PRESERVE to 1 element:"
ReDim Preserve nNumbers(1)
PrintL Join$(nNumbers, ", ")
' -- Now virtual...
PrintL
ReDim nNumbers(3)
nNumbers(1) = 1, 2, 3
Long nVirtual(3) At VarPtr(nNumbers(1))
PrintL "Original virtual (should be 1, 2, 3):"
PrintL Join$(nNumbers, ", ")
PrintL "After REDIM virtual to 1 element (should be 0 and 1, 0, 0):"
ReDim nVirtual(1)
PrintL Join$(nVirtual, ", ") + "<-- this should be zero"
PrintL Join$(nNumbers, ", ")
PrintL
PrintL "Original virtual (should be 1, 2, 3):"
ReDim nVirtual(3)
nVirtual(1) = 1, 2, 3
PrintL Join$(nVirtual, ", ")
PrintL "After REDIM PRESERVE to 1 element (should be 1 and 1, 0, 0):"
ReDim Preserve nVirtual(1) ' -- Not allowed
PrintL Join$(nVirtual, ", ")
PrintL Join$(nNumbers, ", ")
WaitKey
To me, the REDIM for virtual array behaves like REDIM PRESERVE, while REDIM PRESERVE for virtual is not possible to use - this could use some fine tuning.
To allow what Renne needs, we would need another keyword, because leaving the memory as-was is not something default. I would propose for example:
This way it would behave like REDIM PRESERVE + it would leave the "released" memory untouched - no zeroing.