473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Combine 2 Arrays Into Single Array?

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
9 24129
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
Killer42
8,435 Expert 8TB
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
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
1,445 Expert 1GB
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
1,977 1GB
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
Killer42
8,435 Expert 8TB
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
@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
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
Killer42
8,435 Expert 8TB
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

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

Similar topics

35
by: Troll | last post by:
Hi, I need to write a script which reads some data and reports the findings. Just to give you an idea the structure is similar to the following. Data input example: HEADING 1 **********...
7
by: csx | last post by:
Hi everyone! two quick questions relating to arrays. Q1, Is it possible to re-assign array elements? int array = {{2,4}, {4,5}}; array = {2,3}
0
by: JL_327 | last post by:
No one on any of the other boards seem to know In VB.Net this late binding works fine Dim Version As Integer Dim Revision As Integer Dim Wnum As Integer Dim o As System.Array =...
8
by: frekster | last post by:
Hi. I used to be able to do this easily in vb 6 via looping and preserving the source array data/size etc. How can I do this in vb.net? I've been trying for a while now and this should be...
3
by: Schroeder, AJ | last post by:
Hello group, I am a relative PHP newbie and I am trying to combine two arrays together, but I also need to keep the keys of one array intact. What I am doing is two SNMP walks against a Cisco...
2
by: chris | last post by:
I have a few byte arrays that I would like to combine into one array (order needs to be kept). What would be the most efficient way to do this? Thanks for your time, Chris
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
2
by: cmdolcet69 | last post by:
I know have (2) seperate arrays that hold an undefined number of information. I would like to take array-1 and array-2 and create an average array between the two array1 ...
5
by: macca | last post by:
Hi, I'm doing an two ldap_search queries and I need to combine the two results into one single array containing all the results from each but removing duplicates. I have tried built in php...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.