我有这段代码:
rs1 = getResults(sSQL1)
rs2 = getResults(sSQL2)
rs1和rs2以及2D数组。第一个索引表示列数(静态),第二个索引表示行数(动态)。
我需要加入两个数组并将它们存储在rs3中。我不知道rs1和rs2是什么类型的。
答案 0 :(得分:1)
您确定列会匹配吗?因为如果不是这种情况,我不知道你是如何用任何语言的通用方式做的。如果是这种情况,那么您可能会这样做非常:
rs1 = getResults(sSQL1 & " UNION " sSQL2)
答案 1 :(得分: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
答案 2 :(得分: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