By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

Combine 2 Arrays Into Single Array?

P: 28
Hi, I have 2 arrays (Each As a String), and I would like to combine these into a new single array. Is there an easy way of coding this? For example, I want "arrData" and "arrID" to be combined into a new array: "arrTotal". If anyone could give me some coding examples, I'd greatly appreciate it. Thanks!
Sep 5 '07 #1
Share this Question
Share on Google+
9 Replies


VBPhilly
P: 95
Hi, I have 2 arrays (Each As a String), and I would like to combine these into a new single array. Is there an easy way of coding this? For example, I want "arrData" and "arrID" to be combined into a new array: "arrTotal". If anyone could give me some coding examples, I'd greatly appreciate it. Thanks!
This has a ArrayMerge solution that might be just what you need:

http://www.freevbcode.com/ShowCode.Asp?ID=2874
Sep 5 '07 #2

Expert 5K+
P: 8,434
Hi, I have 2 arrays (Each As a String), and I would like to combine these into a new single array. Is there an easy way of coding this? For example, I want "arrData" and "arrID" to be combined into a new array: "arrTotal".
Can you be more speciifc about what you mean by "merged"? Do you want the corresponding values in the arrays to be concatenated/added/multiplied/combined in some way? Do you just want the two arrays to be stuck together "end to end"? Should the values be "interleaved"? Show us some samples of what sort of thing you mean.

Also, what version of VB are you using?
Sep 6 '07 #3

P: 28
Thanks for your replies. I'm using VB 6.0. I basically am building 2 separate "tables" that are being filled with data from a SQL table. The first array bascially contains descriptive data and the 2nd array contains numerical quantitative data. I'm adding SQL data into each array using .movenext and loop. So, I have both arrays containing the data, and I would like to combine them as a new "table". So, nothing will be added or calculated, just a combined new array that contains all the data. Thanks!
Sep 7 '07 #4

QVeen72
Expert 100+
P: 1,445
Hi,

u want a combined resultant array with Distinct Values of both the arrays..? or Simply Merge without any condition...?
If both the array data is in 2 Tables, then u can just get the Results thru SQL Query, u dont have to Populate an array and combine,
Some Query Like :

Expand|Select|Wrap|Line Numbers
  1. Select Col1 From Table1
  2. Union All
  3. Select Col1 From Table2
  4.  
REgards
Veena
Sep 7 '07 #5

hariharanmca
100+
P: 1,977
Hi,

u want a combined resultant array with Distinct Values of both the arrays..? or Simply Merge without any condition...?
If both the array data is in 2 Tables, then u can just get the Results thru SQL Query, u dont have to Populate an array and combine,
Some Query Like :

Expand|Select|Wrap|Line Numbers
  1. Select Col1 From Table1
  2. Union All
  3. Select Col1 From Table2
  4.  
REgards
Veena

Onemore Guesses

Expand|Select|Wrap|Line Numbers
  1. SELECT (tblTableName1.MrgColumn & tblTableName2.MrgColumn) as CombColumn 
  2. FROM tblTableName1 INNER JOIN tblTableName2 ON tblTableName1.IDfield = tblTableName2.IDfield
Just explain you want to ADD one by one or merge columns?
Sep 7 '07 #6

Expert 5K+
P: 8,434
I'm still a bit confused about what is to be in the combined array. Could you show us just a little sample of some data, before and after.

If the "combined" array is supposed to hold some sort of one-to-one relationship (this descriptive-text <=> this numeric-value) then perhaps the simplest would be to define an array (or collection) of a user defined type which holds the two pieces of information. For example...

Expand|Select|Wrap|Line Numbers
  1. Public Type MyStuff
  2.   DescTxt As String
  3.   NumVal As Long
  4. End Type
  5. Dim MyArray(1 To 10) As MyStuff
  6.  
  7. With MyArray(1)
  8.   .DescTxt = "The first descriptive text entry"
  9.   .NumVal = 1234
  10. End With
  11.  
  12. ' And so on...
Sep 7 '07 #7

P: 1
@Killer42
I think He Means...

Dim 1 = abc
Dim 2 = def

3 should be 1 joined to 2 so...
3 = abcdef
Apr 9 '12 #8

P: 51
Expand|Select|Wrap|Line Numbers
  1. 'testing.. :)
  2.  
  3. 'under general declarations
  4. Dim arr1(),arr2(),arr3() As String
  5. Dim i,n As Integer
  6.  
  7. 'let rs handles the recordset
  8.  
  9. 'sub to get records then add to a listbox
  10. rs.Requery
  11. n = rs.RecordCount
  12. Redim arr1(1 To n)
  13. Redim arr2(1 To n)
  14. Redim arr3(1 To n)
  15.  
  16. i = 1
  17. Do Until rs.Eof
  18. arr1(i) = rs!ID
  19. arr2(i) = rs!Name
  20. arr3(i) = arr1(i) & " " & arr2(i)
  21. i = i + 1
  22. rs.MoveNext
  23. Loop
  24.  
  25. For j = 1 To i
  26. List1.add arr3(j)
  27. Next j
  28.  
Apr 10 '12 #9

Expert 5K+
P: 8,434
You may be right waffles. However, it may also be a bit late. That last post of mine was almost 5 years ago, and the OP doesn't appear to have been active here for almost that long.
Apr 22 '12 #10

Post your reply

Sign in to post your reply or Sign up for a free account.