Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VBscript, Merge two arrays into one

Posted on 2006-10-29
4
7,112 Views
Last Modified: 2008-01-09
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 ?
0
Comment
Question by:sebastienbo
  • 2
4 Comments
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17830880

dim j1
dim j2
dim combinedArray()

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

combinedArray = split(j1,"|")
0
 
LVL 19

Accepted Solution

by:
BrianGEFF719 earned 500 total points
ID: 17830884
or just:

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

Expert Comment

by:saravananvg
ID: 17831887
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,
padmaja.
0
 
LVL 5

Author Comment

by:sebastienbo
ID: 17835273
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.

THank you for your help

Sébastien
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question