Function Array Conversions Class

ReDimPreserveVariantCube

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

Signature (Visual Basic / VBA)

Public Function ReDimPreserveVariantCube( _
      ByRef rCube() As Variant _
    , Optional ByVal vLBound1 As Variant _
    , Optional ByVal vUBound1 As Variant _
    , Optional ByVal vLBound2 As Variant _
    , Optional ByVal vUBound2 As Variant _
    , Optional ByVal vLBound3 As Variant _
    , Optional ByVal vUBound3 As Variant _
    ) As Boolean

Code Example

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

Parameters

Parameter Description
rCube Dynamic, three-dimensional array of Variant values that will be redimensioned. rCube 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(rCube, 1)).
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(rCube, 1)).
vLBound2 New lower bound for the second dimension. Defaults to LBound(rCube, 2) if missing or ....
vUBound2 New upper bound for the second dimension. Defaults to UBound(rCube, 2) if missing or ....
vLBound3 New lower bound for the third dimension. Defaults to LBound(rCube, 3) if missing or ....
vUBound3 New upper bound for the third dimension. Defaults to UBound(rCube, 3) if missing or ....

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 any or all bounds of a three-dimensional array while preserving the contents of the elements that existed both before and after. New elements are left Empty.
v1.2 BugFix Renamed argument rMatrix to rCube.