Hi all,
I need to join two arrays with different array item numbers into one array. I tried to join them with the code listed below, but it will only join the array items of the two arrays up to the lower number of the array with the lower item number.
=======================================================
Dim arrItems, Array1, Array2
Array1 = Array("Text1","Text2","Text3","Text4","Text5")
Array2 = Array("Text6","Text7","Text8","Text9")
joinData Array1, Array2
For Each objItem In arrItems
Wscript.Echo objItem
Next
Sub joinData(arrData1, arrData2)
Dim k, i, j
arrItems = Array("") : k = 0
For i = LBound(arrData1) To UBound(arrData1)
For j = LBound(arrData2) To UBound(arrData2)
If i = j Then
arrItems(k) = arrData1(i) & ";" & arrData2(j)
k = k + 1
ReDim PreServe arrItems(k)
Exit For
End If
Next
Next
End Sub
======================================================
When I ran the above code, I got the following result:
Text1;Text6
Text2;Text7
Text3;Text8
Text4;Text9
What I want is the following:
Text1;Text6
Text2;Text7
Text3;Text8
Text4;Text9
Text5;
Even if the second array has only 4 items, I still want the final array to contain the items from the first array with blank data.
If there any way to join the two arrays to contain all items from the array with higher item number even when they have different array item numbers?
Thanks!
CluM09
I need to join two arrays with different array item numbers into one array. I tried to join them with the code listed below, but it will only join the array items of the two arrays up to the lower number of the array with the lower item number.
=======================================================
Dim arrItems, Array1, Array2
Array1 = Array("Text1","Text2","Text3","Text4","Text5")
Array2 = Array("Text6","Text7","Text8","Text9")
joinData Array1, Array2
For Each objItem In arrItems
Wscript.Echo objItem
Next
Sub joinData(arrData1, arrData2)
Dim k, i, j
arrItems = Array("") : k = 0
For i = LBound(arrData1) To UBound(arrData1)
For j = LBound(arrData2) To UBound(arrData2)
If i = j Then
arrItems(k) = arrData1(i) & ";" & arrData2(j)
k = k + 1
ReDim PreServe arrItems(k)
Exit For
End If
Next
Next
End Sub
======================================================
When I ran the above code, I got the following result:
Text1;Text6
Text2;Text7
Text3;Text8
Text4;Text9
What I want is the following:
Text1;Text6
Text2;Text7
Text3;Text8
Text4;Text9
Text5;
Even if the second array has only 4 items, I still want the final array to contain the items from the first array with blank data.
If there any way to join the two arrays to contain all items from the array with higher item number even when they have different array item numbers?
Thanks!
CluM09