<-- Previous || Up || Next -->

Re Dim Preserve Variant Vector Function
Array Conversions Class

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

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

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.
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.
See also:
    ReDimPreserveVariantCube Function
    ReDimPreserveVariantMatrix Function
    BasicExtensions Class
    ReDim Preserve Statement (Visual Basic)
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.

Return to ENTISOFT Home Page

Copyright 1999-2005 Entisoft