0

我有这个代码:

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

rs1 和 rs2 以及二维数组。第一个索引表示列数(静态),第二个索引表示行数(动态)。

我需要加入这两个数组并将它们存储在 rs3 中。我不知道 rs1 和 rs2 是什么类型。

4

3 回答 3

1

你确定这些列会匹配吗?因为如果不是这种情况,我不知道您将如何以任何语言以通用方式进行操作。如果是这种情况,那么您可能可以非常简单地这样做:

rs1 = getResults(sSQL1 & " UNION " sSQL2)
于 2008-10-06T15:58:18.063 回答
1

我已经想通了。事实证明我一直都在做正确的事情,我只差一个。您也不需要第三个数组。

        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           
于 2008-10-06T16:15:20.387 回答
0

我知道这篇文章很旧,但我修改了代码以修复我在执行过程中遇到的一些错误。以下代码示例适用于我:

Sub ConcatRecordSets(ByRef avFirstRS As Variant, ByRef avSecondRS As Variant)

    Dim lIndex1 As Long, lIndex2 As Long
    Dim lFirstRSSize As Long, lSecondRSSize As Long

    ' Redim original array
    lFirstRSSize = UBound(avFirstRS, 2) - LBound(avFirstRS, 2) + 1
    lSecondRSSize = UBound(avSecondRS, 2) - LBound(avSecondRS, 2) + 1
    ReDim Preserve avFirstRS(LBound(avFirstRS, 1) To UBound(avFirstRS, 1), LBound(avFirstRS, 2) To UBound(avFirstRS, 2) + lSecondRSSize)

    ' Add the values from the second array
    For lIndex1 = LBound(avSecondRS, 1) To UBound(avSecondRS, 1)      ' Loop for 1st dimension
        For lIndex2 = LBound(avSecondRS, 2) To UBound(avSecondRS, 2)  ' Loop for 2nd dimension
            avFirstRS(lIndex1, lFirstRSSize + lIndex2) = avSecondRS(lIndex1, lIndex2)
        Next lIndex2
    Next lIndex1

End Sub
于 2012-05-29T19:26:18.090 回答