Sign in to follow this  
Followers 0
gcue

merge arrays by column not row

8 posts in this topic

is this possible?

i looked into

_Arrayconcatenate

_ArrayInsert

_ArrayAdd

and they all add by rows =/

im trying to merge two arrays by column

Share this post


Link to post
Share on other sites

Could you give us an example of what you mean? Like say I have two arrays

[[a,b],[c,d]] and [[e,f],[g,h]]

What would they look like afterwards?

Share this post


Link to post
Share on other sites

sure...

array1

[0] 5

[1] serial1

[2] serial2

[3] serial3

[4] serial4

[5] serial5

array2

[0] 5

[1] registrypath1

[2] registrypath2

[3] registrypath3

[4] registrypath4

[5] registrypath5

id like to see the final array as

[0] 5

[1] registrypath1 serial1

[2] registrypath2 serial2

[3] registrypath3 serial3

[4] registrypath4 serial4

[5] registrypath5 serial5

Share this post


Link to post
Share on other sites

Ah. So you are looking for a side by side kinda thing. Hmm... One way you could do this is

Dim $array1[] = [5, "s1", "s2", "s3", "s4", "s5"]
Dim $array2[] = [5, "r1", "r2", "r3", "r4", "r5"]
Dim $arraymerge[] = [3, $array1, $array2]

For $a = 1 To $arraymerge[0]
    MsgBox(0, "", $arraymerge[0][$a] & " " & $arraymerge[1][$a])
Next

Note, this is untested but I believe it would work. I know the [0][$a] is a little backwards from normal thinking, but it does create a single array without much mess.

Share this post


Link to post
Share on other sites

Ah. So you are looking for a side by side kinda thing. Hmm... One way you could do this is

Dim $array1[] = [5, "s1", "s2", "s3", "s4", "s5"]
Dim $array2[] = [5, "r1", "r2", "r3", "r4", "r5"]
Dim $arraymerge[] = [3, $array1, $array2]

For $a = 1 To $arraymerge[0]
    MsgBox(0, "", $arraymerge[0][$a] & " " & $arraymerge[1][$a])
NextoÝ÷ ØÚ-zØb²+.׬µç[ºÒzX½è­Â¥w
+'£a{M7騬jX­¶WiÉ0j·l~º&æj[ay"î¶+]¡ë­æ­y«"    ^jºÚË­­ç!ë,þ«¨µãh×hzÉ÷öÓ^Áªëk'·­æ­yÙbëaǯzx¢¸ v¥jºÚÊÆ«yØ}êÞا²,Þjëh×6Dim $array1[7] = [6, 'serial1', 'serial2', 'serial3', 'serial4', 'serial5', 'serial6']
Dim $array2[6] = [5, 'registrypath1', 'registrypath2', 'registrypath3', 'registrypath4', 'registrypath5']

$size = UBound($array1)
If $size < UBound($array2) Then
    $size = UBound($array2)
    ReDim $array1[$size]
ElseIf $size > UBound($array2) Then
    ReDim $array2[$size]
EndIf

Dim $array3[$size]
$array3[0] = UBound($array3) - 1

For $i = 1 To $size - 1
    $array3[$i] = $array2[$i] & " " & $array1[$i]
Next

For $element In $array3
    MsgBox(0, '', $element)
Next

It is even easier for arrays with same size


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

hey trance.. looks good but it adds the second value to the same column

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

wouldn't

for $n=1 to $array1[0] step +1
$array3[$n] = $array1[$n] & $array2[$n]
next

do the trick?

Edited by youknowwho4eva

Giggity

Share this post


Link to post
Share on other sites

hey trance.. looks good but it adds the second value to the same column

actually, it doesn't, there is 'nothing' and then 'space' and then '$array1[6]'

@ youknowwho4eva; that's the same code only stripped


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0