We help IT Professionals succeed at work.

# VBscript, Merge two arrays into one

on
Medium Priority
10,240 Views
Is there a function build into vbscript that permits me to join two or more arrays to one ?
If not can such function be written ?
Comment
Watch Question

## View Solution Only

Commented:

dim j1
dim j2
dim combinedArray()

j1 = join(array1,"|")
j2 = join(array2,"|")
j1 = j1 & "|" & j2

combinedArray = split(j1,"|")
Commented:
or just:

dim combinedArray()
combinedArray = split(join(array1,"|") & "|" & join(array2,"|") ,"|") 'combines array1 & array2

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
Hello Sir,

Here's a quick script I came up with to do this. With this code, the arrays don't have to be the same size. It will simply combine two individual arrays into one big one by using a dynamic third array (since you may/may not know how big the first two will be.)

<SCRIPT LANGUAGE="VBScript">
<!--
Dim intArray1(8)
Dim intArray2(9)
Dim intNewArray()

Public Sub cmdScramble_OnClick()

intValue = 1

for x = 0 to UBound(intArray1)-1
intArray1(x) = intValue
intValue = intValue + 1
next

for x = 0 to UBound(intArray2)-1
intArray2(x) = intValue
intValue = intValue + 1
next

ReDim intNewArray(UBound(intArray1)+UBound(intArray2))

for x = 0 to UBound(intArray1)-1
intNewArray(x) = intArray1(x)
next

y = 0

for x = UBound(intArray1) to (Ubound(intArray1) + UBound(intArray2))
intNewArray(x) = intArray2(y)
y = y + 1
next

for x = 0 to ubound(intNewArray)-1
msgbox intNewArray(x)
next

End sub

-->

</SCRIPT>

with regards,

Commented:
Thanks BrianGEFF719 ,

Your solution was short,powerfull and simple.

padmaja you had a nice function too but it is much too large, but thanks for the effort.

##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile