Dynamic Multidimensional String Array Syntax?

aerowrx

New member
Local time
Today, 04:07
Joined
Dec 15, 2011
Messages
1
I have the basic string array code down, but i'd like to have 3 columns and X number of rows. So I want it to expand dynamically as I add things to it. How should I append to the multidimensional array?

Code:
Dim yieldTable() As String
Dim blDimensioned As Boolean

Do While Not rst.EOF
  Do While Not rst2.EOF
    If rst!ID = rst2!ID Then ' If Material/Product ID = YieldTable ID
        If blDimensioned = True Then
            'Extend array one element larger than current upper bound
            ReDim Preserve yieldTable(0 To UBound(yieldTable) + 1) As Integer
        Else
            'No, so dimensioned it and flag it as dimensioned
            ReDim yieldTable(0 To 2) As Integer
            blDimensioned = True
        End If
        yieldTable(UBound(yieldTable) = ' "String 1" "String 2" "String 3" ????
               
        rst2.MoveNext
    Loop
    rst2.Close
.......
....
 
Last edited:
ReDim Preserve MyArray(0 To x, 0 to y)

UBx = UBound(MyArray,1)
UBy = UBound(MyArray,2)

Then use a loop to go through the individual array members and add the values.

Note that ReDim Preserve cannot be used to add another dimension.

BTW: If you can get the values into a recordset there is the GetRows Method of the recordset that will write the values to an array. Also, it is often clearer and easier to work directly with a recordset in a loop than it is with multidimensional arrays so consider carefully if you actually need an array.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom