Recently, I was working on a VB application. It was using an array that was creating using ADO's GetRows() method. I found that I needed to add an additional column to the array, based on some calculations that occured from within VB.
First thing I tried was ReDim Preserve. That didn't work because you can not change the size of any dimension except the last when you want to use Preserve. Shoot.
So, what I did was created a second array that was one index larger in the first dimension. I then wrote this function to move the contents of the first array into the second:
Private Sub privMove2DArrayContents(ByVal sourceArray As Variant, ByRef targetArray As Variant)
Dim iLowerBound As Integer
Dim iUpperBound As Integer
For iLowerBound = 0 To UBound(sourceArray, 1)
For iUpperBound = 0 To UBound(sourceArray, 2)
targetArray(iLowerBound, iUpperBound) = sourceArray(iLowerBound, iUpperBound)
Next
Next
End Sub
|