Update: This is what resulting data should look like:
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
I've written code to add an array to each "row" of an existing array in VBScript. I doesn't error out, but I can't figure out if I'm doing it correctly. Anytime I try to access data from the column that I placed the new array, I get nothing. Can someone show me the correct syntax for adding an array to an existing array in Vbscript?
Right now, I am looping through each row and adding my array to the end. Like this:
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
Update: Let me try to better explain my above code. 1. ReDim Preserve arComm... takes my existing array of 7 columns and add's an 8th column to it. UBound(arrComm) makes sure that it sets it to the correct amount of existing rows.
Next I create a new array called newMembers
Then I have to specify the length of newMembers so I loop through the array I am pulling my newMembers from (arrMembers) and get a count of the amount from arrMembers that will be placed into newMembers. (y)
Then once I have this count, I Redim newMembers with (y) and 9 columns
Then I go through arrMembers and pull the amount that matches my criteria into newMembers
Then I add my newly created array called newMembers to the last column of the arrComm array.
Then I circle back up, go to the next row of the arrComm array and start over, creating another newMembers array, this time different amount of rows, and then finally adding it to the next row of the arrComm array. And over and over until I have added a new array to the last column of arrComm for every single row.