Function Array Conversions Class

ReDimPreserveVariantVector

"Re-dimension Preserve Variant Vector" Redimensions a one-dimensional array of Variants. Preserves all elements that existed both before and after the re-dimension.

Signature (Visual Basic / VBA)

Public Function ReDimPreserveVariantVector( _
      ByRef rVector() As Variant _
    , Optional ByVal vLBound1 As Variant _
    , Optional ByVal vUBound1 As Variant _
    ) As Boolean

Code Example

    Assuming
       Dim avarNums() As Variant
       ReDim avarNums(0 To 5)
       avarNums(1) = .45
       avarNums(2) = .12
       ' ....
    for example
       ' Same as ReDim Preserve avarNums(-5 To 5)
       ' if Visual Basic would allow it.
       ReDimPreserveVariantVector(avarNums(), -5) = True
    leaves
       avarNums(1) = .45
       avarNums(2) = .12
       ' Etc.

Parameters

Parameter Description
rVector Dynamic, one-dimensional array of Variant values that will be redimensioned. rVector must already be dimensioned before it is passed to this function or else an error will occur.
vLBound1 New lower bound for the first dimension. If vLBound1 is missing or Null or cannot be fixed-up to a number, it defaults to the current lower bound for the dimension (LBound(rVector)).
vUBound1 New upper bound for the first dimension. If vUBound1 is missing or Null or cannot be fixed-up to a number, it defaults to the current upper bound for the dimension (UBound(rVector)).

Return Value

Function currently always returns True.

Notes & Version History

Summary This function works around a limitation in Visual Basic's ReDim Preserve statement. It allows you to redimension the lower bound of a one-dimension array while preserving the contents of the elements that existed both before and after. New elements are left Empty.