Search code examples
arraysms-accessvbaconcatenation

How do I concatenate two multi-dimensional arrays in VB?


I've got this code:

rs1 = getResults(sSQL1)
rs2 = getResults(sSQL2)

rs1 and rs2 and 2D arrays. The first index represents the number of columns (static) and the second index represents the number of rows (dynamic).

I need to join the two arrays and store them in rs3. I don't know what type rs1 and rs2 are though.


Solution

  • I've figured it out. Turns out I was doing it the right way all along, I was just off by one. You don't need a third array either.

            aRS_RU = rowsQuery(sSQL & ", 'RU'")
            aRS_KR = rowsQuery(sSQL & ", 'KR'")
    
            uboundRU1 = UBound(aRS_RU, 1)
            uboundRU2 = UBound(aRS_RU, 2)
            uboundKR2 = Ubound(aRS_KR, 2)
    
            ' Redim original array
            ReDim Preserve aRS_RU(uboundRU1, uboundRU2 + uboundKR2 + 1 )
            uboundRU2 = UBound(aRS_RU, 2)
    
            ' Add the values from the second array            
            For m = LBound(aRS_KR, 1) To UBound(aRS_KR, 1)      'Loop for 1st dimension
                For n = LBound(aRS_KR, 2) To UBound(aRS_KR, 2)  'Loop for 2nd dimension
                    aRS_RU(m, uboundRU2 + n) = aRS_KR(m,n)
                Next
            Next