Sign in to follow this  
Followers 0
Chimaera

Adding 2 arrays together

21 posts in this topic

Been working on this

$a1 = '1|2'
Local $ab1 = StringSplit($a1, "|")
_ArrayDisplay($ab1)
$b1 = '3|4'
Local $ab2 = StringSplit($b1, "|")
_ArrayDisplay($ab2)

$c1 = _ArrayConcatenate($ab1,$ab2)
ConsoleWrite( @error & @CRLF)
_ArrayDisplay($c1)

didnt work so then this

#include <Array.au3>

$a1 = '1|2'
Local $ab1 = StringSplit($a1, "|")
_ArrayDisplay($ab1)
$b1 = '3|4'
Local $ab2 = StringSplit($b1, "|")
_ArrayDisplay($ab2)

;~ $c1 = _ArrayConcatenate($ab1,$ab2)
;~ ConsoleWrite( @error & @CRLF)
;~ _ArrayDisplay($c1)

Local $c1[2][2] = [[$ab1], [$ab2]]
ConsoleWrite( @error & @CRLF)
_ArrayDisplay($c1)

It creates 2 colums but not the data, what im trying to end up with is this

 

1 3

2 4

Any suggestions where im going wrong?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This works? Please pay attention to the return value of _ArrayConcatenate().

#include <Array.au3>

Local $sString_1 = '1|2'
Local $aSplit = StringSplit($sString_1, '|', $STR_NOCOUNT)
Local $aArray_1[1][UBound($aSplit)]
For $i = 0 To UBound($aSplit) - 1
    $aArray_1[0][$i] = $aSplit[$i]
Next

Local $sString_2 = '3|4'
$aSplit = StringSplit($sString_2, '|', $STR_NOCOUNT)
Local $aArray_2[1][UBound($aSplit)]
For $i = 0 To UBound($aSplit) - 1
    $aArray_2[0][$i] = $aSplit[$i]
Next

_ArrayConcatenate($aArray_1, $aArray_2)
_ArrayDisplay($aArray_1)
Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Or this...

#include <Array.au3>

Local $sString_1 = '1|2'
Local $aSplit = StringSplit($sString_1, '|', $STR_NOCOUNT)
Local $aArray_1 = OneToTwoArray($aSplit)

Local $sString_2 = '3|4'
$aSplit = StringSplit($sString_2, '|', $STR_NOCOUNT)
Local $aArray_2 = OneToTwoArray($aSplit)

_ArrayConcatenate($aArray_1, $aArray_2)
_ArrayDisplay($aArray_1)

Func OneToTwoArray(ByRef $aArray)
    Local $iUBound = UBound($aArray)
    If $iUBound > 0 Then
        Local $aReturn[1][$iUBound]
        For $i = 0 To $iUBound - 1
            $aReturn[0][$i] = $aArray[$i]
        Next
        Return $aReturn
    EndIf
    Return Null
EndFunc   ;==>OneToTwoArray
Edit: Reused $iUBound. But the code is exactly the same. Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Why not play with _ArrayTranspose (integrated)  :)

#include <Array.au3>

$a1 = '1|2'
Local $ab1 = StringSplit($a1, "|", 2)
_ArrayTranspose($ab1)
$b1 = '3|4'
Local $ab2 = StringSplit($b1, "|", 2)
_ArrayTranspose($ab2)

_ArrayConcatenate($ab1,$ab2)
_ArrayTranspose($ab1)
_ArrayDisplay($ab1)

Edit

simpler

#include <Array.au3>

$a1 = '1|2'
Local $ab1 = StringSplit($a1, "|", 2)
_ArrayTranspose($ab1)
$b1 = '3|4'
_ArrayAdd($ab1, $b1)

_ArrayTranspose($ab1)
_ArrayDisplay($ab1)
Edited by mikell

Share this post


Link to post
Share on other sites

Hmmm  thx guys, maybe im not explaining it very well none of those work as expected

@ guinness yours only show 

Col 0 Col1

  1        2

@ mikell

Col0

1

2

3

4

 

Im after the first array in col0 and the second array in col1

 

Col 0  Col1

  1        3

  2        4

 

Im trying to match in real life an installer and a silent switch

Share this post


Link to post
Share on other sites

I am sure my first example was to your specification.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Are you using v3.3.12.0?

Edit: I see mine output

1 2

3 4

But it still prints different to your screenshot.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Starting AutoIt3Wrapper v.2.1.4.4 SciTE v.3.3.7.0 ;  Keyboard:00000809  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0409  Keyboard:00000809  OS:WIN_81/  CPU:X64 OS:X64)
>Running AU3Check (3.3.10.2) 
 
Just updated to Running AU3Check (3.3.12.0)  from:C:Program Files (x86)AutoIt3
And it shows correctly now albiet the wrong way round
 
yours

Col 0  Col1

  1        2

  3        4

 
what im after

Col 0  Col1

  1        3

  2        4

 

but ill keeep working at it

Thx again

Edited by Chimaera

Share this post


Link to post
Share on other sites

Did you try mikell's code?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Here another, maybe freaky, way:
 

#include <Array.au3>

$a1 = '1|2'
Local $ab1 = StringSplit(StringReverse($a1), "|", 2)
_ArrayTranspose($ab1)
$b1 = '3|4'
_ArrayAdd($ab1, StringReverse($b1))
$aResult = _ArrayRotate($ab1, -90)

_ArrayDisplay($aResult)

Func _ArrayRotate($aArray, $iDeg) ;coded by UEZ 2012 build 2012-02-15
    If Not IsArray($aArray) Then Return SetError(1, 0, 0) ;not an array
    If Not UBound($aArray, 0) = 2 Then Return SetError(2, 0, 0) ;not a 2D array
    If Mod($iDeg, 90) Then Return SetError(3, 0, 0) ;only 90° rotations allowed
    Local $i, $j, $k = 0, $l = 0
    Switch $iDeg
        Case 90, -270
            Local $aRotated[UBound($aArray, 2)][UBound($aArray)]
            For $i = 0 To UBound($aArray, 2) - 1
                For $j = UBound($aArray) -1 To 0 Step - 1
                    $aRotated[$i][$k] = $aArray[$j][$i]
                    $k += 1
                Next
                $k = 0
            Next
            Return $aRotated
        Case 270, -90
            Local $aRotated[UBound($aArray, 2)][UBound($aArray)]
            For $i = UBound($aArray, 2) - 1 To 0 Step - 1
                For $j = 0 To UBound($aArray) - 1
                    $aRotated[$l][$k] = $aArray[$j][$i]
                    $k += 1
                Next
                $l += 1
                $k = 0
            Next
            Return $aRotated
        Case 180, -180
            Local $aRotated[UBound($aArray)][UBound($aArray, 2)]
            For $i = UBound($aArray) - 1 To 0 Step - 1
                For $j = UBound($aArray, 2) - 1 To 0 Step - 1
                    $aRotated[$l][$k] = $aArray[$i][$j]
                    $k += 1
                Next
                $l += 1
                $k = 0
            Next
            Return $aRotated
    EndSwitch
EndFunc

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

There are different methods, but you should try to understand how they work. In that sense my illustration is the simplest to learn from. You must (at least) be able to work this out for yourself using native functions only. It is also the most efficient method in this particular case: because it requires no transposition.

Consider this: what do you intend to do when the arrays are of different sizes?

Edited by czardas

Share this post


Link to post
Share on other sites

#Include <array.au3>
Opt("MustDeclareVars",1)
Local $a1 = '1|2'
Local $ab1 = StringSplit($a1, "|",2)
_ArrayDisplay($ab1)
Local $b1 = '3|4'
Local $ab2 = StringSplit($b1, "|",2)
_ArrayDisplay($ab2)
Local $c1 = _CombineArrays($ab1, $ab2)
_ArrayDisplay($c1)
Func _CombineArrays(ByRef $Array, ByRef $Array2)
    Local $CMax = UBound($Array)
    Local $Array3[$CMax][2]
    $CMax -= 1
    For $C = 0 to $CMax
        $Array3[$C][0] = $Array[$C]
        $Array3[$C][1] = $Array2[$C]
    Next
    Return $Array3
EndFunc

I noticed czardas' code after I already typed this up. He does in fact have the most efficient solution. I decided to post what I had anyway, in case you wanted to see a more general implementation.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Consider this: what do you intend to do when the arrays are of different sizes?

 They wont be because each exe has a silent switch and/or doesn't which is a blank space , this now loads the exes from one part of the ini file and the switches from another like this example and lines them up ready for use.

post-60350-0-35739200-1404147885_thumb.p

This is just a small part of the whole obviously but you will get the idea.

Im probably not going about this the best way but you kinda go with what you know i guess.

Many thanks to all for the help

Edited by Chimaera

Share this post


Link to post
Share on other sites

Why do you want one 2D array instead of 2x 1D arrays? It's much easier to use 2x 1D arrays.

The Ubound of both 1D arrays must be the same thus you can read one array with the path and associate the parameters from the 2nd array.

 

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

UEZ makes a good point.

In any case, the orientation of your 2D array is irrelevant. When reading or writing to an array, you can loop first through columns followed by rows, or vice versa. You can loop either backwards or forwards. The standard layout of a table (or 2D array) is for aesthetic purposes only. Think of a chess game: it doesn't make any difference which side of the board you sit or which colour pieces are yours. The only difference is your own visual perspective.

Edited by czardas

Share this post


Link to post
Share on other sites

I'm not sure it makes any difference to me as long as the switch is postioned at the end of the program, its more a way of keeping the 2 together so i can access the data

I haven't got as far as how to call the installer and the switch yet but ill get to it

I guess im just working towards a way of holding the data together, i suppose i could have pulled it from an excel sheet who knows..

I still haven't worked out the msi installers which will have to be in Case statements i think, early days yet

Share this post


Link to post
Share on other sites

Chimaera,

A generalized way of concatenating arrays such that each array is a column of the reuslting 2D array.  The arrays can be of any size.

#include <array.au3>

local $a1[20] = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0]
local $a2[10] = [1,2,3,4,5,6,7,8,9,0]
local $a3[50] = ['','',3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0]
local $a4[5] = [1,2,3,4,5]
local $ax[1]
local $MyGoofyArray[3]  =   ['Mo', 'Larry', 'Curly']
local $a5[7] = [1,2,3,4,5,6,7]

local $a10 = _array_combine($a1,$a2,$a3,$ax,$a4,$a5,$MyGoofyArray)

_arraydisplay($a10)

func _array_combine($arr1,$arr2,$arr3=0,$arr4=0,$arr5=0,$arr6=0,$arr7=0,$arr8=0,$arr9=0,$arr10=0)

    ;-----------------------------------------------------------------------------------------------------------------
    ; combine 2 to 10 1D arrays into 1 2D array
    ;-----------------------------------------------------------------------------------------------------------------

    ; ensure at least two arrays
    if not IsArray($arr1) or not IsArray($arr2) then return seterror(1,0,0)

    ; find # of arrays passed ($1 = # of arrays)
    for $1 = 1 to 10
        if not isarray(eval("arr" & $1)) then ExitLoop
    Next

    ; set # of cols variable to # of arrays in parameter
    local $num_cols = $1 - 1
    local $max_rows = 0

    ; set # elements to largest array passed
    for $1 = 1 to $num_cols
        if ubound(eval("arr" & $1)) - 1 > $max_rows then $max_rows = ubound(eval("arr" & $1))
    next

    ConsoleWrite('Formatting target array as ' & $num_cols & ' columns and ' & $max_rows & ' elements.' & @LF)

    ; define result array
    local $aTarget[$max_rows][$num_cols], $aTemp

    ; populate result array
    for $1 = 0 to $num_cols -1
        $aTemp = eval("arr" & $1+1)
        for $2 = 0 to ubound($aTemp) - 1
            $aTarget[$2][$1] = $aTemp[$2]
        Next
    next

    return $aTarget

endfunc

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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