Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combine/Join Two Arrays 2

Status
Not open for further replies.

MrMeric

Technical User
Apr 1, 2004
48
US
I must be thinking too hard because I can't get this to work for the life of me.

How would I combine two arrays into one?

i.e.
----------------
aOne(0) = "zero"
aOne(1) = "one"

aTwo(0) = "two"
aTwo(1) = "three"
aTwo(2) = "four"
----------------

I would like to somehow combine these two, and make one array.

How do I do this?
 
The old fashioned way
Dim aThree() as String
dim iNbr as Integer
iNbr = Ubound(aOne) + 1 Ubound(aTwo) + 1
Redim aThree(iNbr - 1)
Dim I as Integer
Dim J as Integer
J = -1
For I = 0 To Ubound(aOne)
J = J + 1
aThree(j) = aOne(i)
Next
For I = I To Ubound(aTwo)
J = J + 1
aThree(j) = aTwo(I)
Next

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Just another thought...

Use the Split/Join combination.
___
[tt]
Private Sub Form_Load()
Dim aOne(1) As String, aTwo(2) As String
aOne(0) = "zero"
aOne(1) = "one"

aTwo(0) = "two"
aTwo(1) = "three"
aTwo(2) = "four"

Dim aThree() As String, N As Long

aThree = Split(Join(aOne, vbNullChar) & vbNullChar & Join(aTwo, vbNullChar), vbNullChar)

For N = 0 To UBound(aThree)
Debug.Print aThree(N)
Next
End
End Sub[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top