473,782 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combine 2 Arrays Into Single Array?

28 New Member
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 24198
VBPhilly
95 New Member
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 Recognized Expert Expert
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 "interleave d"? Show us some samples of what sort of thing you mean.

Also, what version of VB are you using?
Sep 6 '07 #3
nico3334
28 New Member
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 Recognized Expert Top Contributor
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 Top Contributor
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 Recognized Expert Expert
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
waffles05
1 New Member
@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
rekedtechie
51 New Member
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 Recognized Expert Expert
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
3685
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 ********** ColumnA ColumnB ColumnC ColumnD ColumnE
7
11778
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
1527
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 = System.Array.CreateInstance (GetType(Single), 1)
8
4592
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 an easy task but it just isn't clicking. For some reason, the preserve doesn't seem to be working.
3
8211
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 router in which I expect the script to return the interface number along with a small description of the interface type, like this: Array (
2
7906
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
2449
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 of different lengths (e.g. usually between 25 and 45 rows. The columns in each file have the same length). The text files have been numbered sequentially e.g. cb0, cb1, cb2 and so on. I would like to read the data from each text file into...
2
2191
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 array2 arrayAVG 4096 4095 4095.5 4071 4012 4041.5 4000 3812 ...
5
3599
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 functions such as array_merge (which gives me duplicates) and array_unique which does not work either.
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9479
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10311
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8967
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7492
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6733
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.