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!
Combine 2 Arrays Into Single Array?
Collapse
X
-
-
Originally posted by nico3334Hi, 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!
-
Originally posted by nico3334Hi, 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".
Also, what version of VB are you using?Comment
-
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!Comment
-
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 :
[code=VB]
Select Col1 From Table1
Union All
Select Col1 From Table2
[/code]
REgards
VeenaComment
-
Originally posted by QVeen72Hi,
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 :
[code=sql]
Select Col1 From Table1
Union All
Select Col1 From Table2
[/code]
REgards
Veena
Onemore Guesses
[code=sql]
SELECT (tblTableName1. MrgColumn & tblTableName2.M rgColumn) as CombColumn
FROM tblTableName1 INNER JOIN tblTableName2 ON tblTableName1.I Dfield = tblTableName2.I Dfield[/code]
Just explain you want to ADD one by one or merge columns?Comment
-
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...
[CODE=vb]Public Type MyStuff
DescTxt As String
NumVal As Long
End Type
Dim MyArray(1 To 10) As MyStuff
With MyArray(1)
.DescTxt = "The first descriptive text entry"
.NumVal = 1234
End With
' And so on...[/CODE]Comment
-
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...
[CODE=vb]Public Type MyStuff
DescTxt As String
NumVal As Long
End Type
Dim MyArray(1 To 10) As MyStuff
With MyArray(1)
.DescTxt = "The first descriptive text entry"
.NumVal = 1234
End With
' And so on...[/CODE]
Dim 1 = abc
Dim 2 = def
3 should be 1 joined to 2 so...
3 = abcdefComment
-
Code:'testing.. :) 'under general declarations Dim arr1(),arr2(),arr3() As String Dim i,n As Integer 'let rs handles the recordset 'sub to get records then add to a listbox rs.Requery n = rs.RecordCount Redim arr1(1 To n) Redim arr2(1 To n) Redim arr3(1 To n) i = 1 Do Until rs.Eof arr1(i) = rs!ID arr2(i) = rs!Name arr3(i) = arr1(i) & " " & arr2(i) i = i + 1 rs.MoveNext Loop For j = 1 To i List1.add arr3(j) Next j
Comment
Comment