Solved

VBscript, Merge two arrays into one

Posted on 2006-10-29
4
6,772 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
Comment Utility

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
Comment Utility
or just:

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

Expert Comment

by:saravananvg
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now