Jump to content

Merging Arrays


Recommended Posts

Hello

Can anyone help me with merging two arrays into third one, however first array needs to be in 1st dimension and the second array must be in second dimension.

What I want to do is to have an array with software names and their versions in the same line so I can write it to file.

Thank you in advance

Link to comment
Share on other sites

If the two arrays have the same number of items:

Dim $Array3[UBound ($Array1)][2]

For $i = 0 To UBound ($Array1) - 1
    $Array3[$i][0] = $Array1[$i]
    $Array3[$i][1] = $Array2[$i]
Next

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

Yep, here's the pseudo syntax:

$i = 1 ; or 0 depending on your setup

While $Array1 <> "" ; here im pre-supposing that your two first arrays are alike

$Array3[$i] = $Array1 & $Array2[1][$i] ; again i don't know ur particular setup, please always supply code examples in the future

$i += 1

WEnd

Cheers,

Sunaj

Hello

Can anyone help me with merging two arrays into third one, however first array needs to be in 1st dimension and the second array must be in second dimension.

What I want to do is to have an array with software names and their versions in the same line so I can write it to file.

Thank you in advance

Link to comment
Share on other sites

Yep, here's the pseudo syntax:

$i = 1 ; or 0 depending on your setup

While $Array1 <> "" ; here im pre-supposing that your two first arrays are alike

$Array3[$i] = $Array1 & $Array2[1][$i] ; again i don't know ur particular setup, please always supply code examples in the future

$i += 1

WEnd

Cheers,

Sunaj

I believe what he meant is that he has two arrays, with one dimension each, and wants to merge these two arrays into a two-dimensions array. In this example you created an array of the concatenated content of the first array and the second dimension of the first index of the second array.

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

That is the code I have

Local $array_reg_values[1][1], $array_sub_values[1][1], $array_sub_values_Versions[1][1], $azbArray[1][1]

Local $key = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"

For $a = 1 To 1000

$reg_values = RegEnumKey($key, $a)

If StringInStr($reg_values, "No more data is") = 0 Then

_ArrayAdd($array_reg_values, $reg_values)

EndIf

Next

$array_reg_values[0] = UBound($array_reg_values) - 1

For $b = 1 To $array_reg_values[0]

$sub_key = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall" & "\" & $array_reg_values[$b]

$reg_sub_values = RegRead($sub_key, "DisplayName")

_ArrayAdd($array_sub_values, $reg_sub_values)

Next

$array_sub_values[0] = UBound($array_sub_values) - 1

For $c = 1 To $array_sub_values[0]

If $array_sub_values[$c] = "" Then

$array_sub_values[$c] = $array_reg_values[$c]

EndIf

Next

For $d = 1 To $array_sub_values[0]

$sub_key = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall" & "\" & $array_reg_values[$d]

$reg_sub_values_versions = RegRead($sub_key, "DisplayVersion")

_ArrayAdd($array_sub_values_Versions, $reg_sub_values_versions)

Next

I would like to have array $reg_sub_values and array $reg_sub_values_versions merged into one 2dimensional array, so software name and its version is in the same line when I wrote it to file. Can anybode advise ? Thank you

Link to comment
Share on other sites

It's not a good idea to merge an array "horizontally" there is a good chance your data will be out of sync. You are better off declaring the master array from the beginning, and every time you write to Array1 and Array2, you will also write to MasterArray[0] and MasterArray[1] respectively.

Link to comment
Share on other sites

Here is an easier version of your script...

#include<array.au3>

Local $key = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"

Local $MasterArray[1][3]

$count = 1
While 1
    $value = RegEnumKey($key, $count)
    If @Error Then ExitLoop
    
    Redim $MasterArray[$count + 1][3]
    
    ;Store element count
    $MasterArray[0][0] = $count
    
    ;Store RegKey
    $MasterArray[$count][0] = $value
    
    ;Store DisplayName
    $MasterArray[$count][1] = RegRead($key & "\" & $value, "DisplayName")
    
    ;Store DisplayVersion
    $MasterArray[$count][2] = RegRead($key & "\" & $value, "DisplayVersion")
    $count += 1
WEnd

_ArrayDisplay($MasterArray)
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...