更新:这是结果数据的样子:
arrComm rows 0-6
454-45-45 45345-3454 FIN Elected Finance Committee Details More Details
343-343-3 343-944244 COM Appointed Comm Committee Details More Details
arrComm added row 7 that has array of all members of that committee
This below array is named newMembers and 1 array for each row is added to the
arrComm with this code: arrComm(j,7) = newMembers
454-45-45 John S Smith Chair 2003 2005
454-45-45 Sara T Jones VP 2012 2013
454-45-45 Tim R Jane Pres 2011 2014
我编写了代码来向 VBScript 中现有数组的每个“行”添加一个数组。我没有出错,但我不知道我是否做得正确。每当我尝试从放置新数组的列中访问数据时,我什么也得不到。有人可以告诉我在 Vbscript 中将数组添加到现有数组的正确语法吗?
现在,我正在遍历每一行并将我的数组添加到末尾。像这样:
ReDim Preserve arrComm(UBound(arrComm), 7)
'Loop through Committee Array and add Members Array
Dim newMembers()
For j = 0 to UBound(arrComm)
'create a new array out of Members for each committee
cmt_key = arrComm(j,0)
'First find count of Members array that matches committee
y=0
For s = 0 to UBound(arrMembers)
If arrMembers(s,0) = cmt_key Then
y=y+1
End If
Next
'Next build new array only with those members that match committee
Redim newMembers(y,8)
'Now loop through Original Members Array and add to New Members Array
y=0
For s = 0 to UBound(arrMembers)
If arrMembers(s,0) = cmt_key Then
newMembers(y,0) = arrMembers(s,0)
newMembers(y,1) = arrMembers(s,1)
newMembers(y,2) = arrMembers(s,2)
newMembers(y,3) = arrMembers(s,3)
newMembers(y,4) = arrMembers(s,4)
newMembers(y,5) = arrMembers(s,5)
newMembers(y,6) = arrMembers(s,6)
newMembers(y,7) = arrMembers(s,7)
newMembers(y,8) = arrMembers(s,8)
y=y+1
End If
Next
'Now finally add newly created members array to Committee array
arrComm(j,7) = newMembers(y,8)
Next
更新:让我试着更好地解释我上面的代码。1. ReDim Preserve arComm... 采用我现有的 7 列数组并添加第 8 列。UBound(arrComm) 确保将其设置为正确数量的现有行。
接下来我创建一个名为 newMembers 的新数组
然后我必须指定 newMembers 的长度,所以我循环遍历从 (arrMembers) 中拉出我的 newMembers 的数组,并从 arrMembers 中获取将放入 newMembers 的数量。(y)
然后,一旦我有了这个计数,我用 (y) 和 9 列 Redim newMembers
然后我通过 arrMembers 并将符合我的条件的金额提取到 newMembers
然后我将新创建的名为 newMembers 的数组添加到 arrComm 数组的最后一列。
然后我重新循环,转到 arrComm 数组的下一行并重新开始,创建另一个 newMembers 数组,这次不同数量的行,最后将它添加到 arrComm 数组的下一行。一遍又一遍,直到我为每一行添加一个新数组到 arrComm 的最后一列。