Jump to content

_ArrayAdd To Multi-Dimensional Array..?


Recommended Posts

is there any way to add values across a ROW to the end of an existing Multi-Dimensional array in a way like _ArrayAdd can do to a 1 dimensional array..??

or do you just have to specify each grid cell by making a variable for each one like:

Dim $Grid[2][3]
$Grid[0][0]="000"
$Grid[0][1]="111"
$Grid[0][2]="222"

$Grid[1][0]="000"
$Grid[1][1]="111"
$Grid[1][2]="222"
Link to post
Share on other sites

No standard UDF, but I guess there has to be something in the examples thread. I do it myself by Redim()ing the array and looping through values to set.

Link to post
Share on other sites

But the array I'm creating cant be set to a specific row number..

I need it to always have 5 Columns but the rows are going to fluctuate because I will be adding and removing rows every so often..

so I need a way to Add data across a new Row at the bottom of a Multi-Dimensional array and also a way to remove the whole "Row 0" out of the same Multi-Dimensional array..

Link to post
Share on other sites

Yeah, I do it by Redim()ing the array and looping :D , take a look at the array functions and you'll see that they do exactly that... so look into the examples for a custom UDF or do it this way.

Link to post
Share on other sites

; help files ARE helpful just go through the info on ubound and redim

here's an example of redimensioning arrays and adding information to it..

; list allvisible windows
#include <Array.au3>

$var = WinList()
Dim $list[1][1]

For $i = 1 To $var[0][0]
    If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
        ReDim $list[UBound($list) + 1][2]; <-----  if u need to redim the second dimension, check help file for redim and ubound.
        $list[UBound($list) - 1][0] = $var[$i][0]
        $list[UBound($list) - 1][1] = $var[$i][1]
    EndIf
Next
_ArrayDisplay($var)
_ArrayDisplay($list)

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc
Link to post
Share on other sites

is there any way to add values across a ROW to the end of an existing Multi-Dimensional array in a way like _ArrayAdd can do to a 1 dimensional array..??

No standard UDF, but I did post a 2D version of an Array.au3 function, called __ArrayConcatenate(). Note the double underscore in the name. It will handle either 1D or 2D functions. The original post includes a demo script.
; #FUNCTION# =====================================================================
; Name...........: __ArrayConcatenate
; Description ...: Concatenate two 1D or 2D arrays
; Syntax.........: __ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource)
; Parameters ....: $avArrayTarget - The array to concatenate onto
;                 $avArraySource - The array to concatenate from - Must be 1D or 2D to match $avArrayTarget,
;                                  and if 2D, then Ubound($avArraySource, 2) <= Ubound($avArrayTarget, 2).
; Return values .: Success - Index of last added item
;                 Failure - -1, sets @error to 1 and @extended per failure (see code below)
; Author ........: Ultima
; Modified.......: PsaltyDS - 1D/2D version, changed return value and @error/@extended to be consistent with __ArrayAdd()
; Remarks .......:
; Related .......: __ArrayAdd, _ArrayPush
; Link ..........;
; Example .......; Yes
; ===============================================================================
Func __ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource)
    If Not IsArray($avArrayTarget) Then Return SetError(1, 1, -1); $avArrayTarget is not an array
    If Not IsArray($avArraySource) Then Return SetError(1, 2, -1); $avArraySource is not an array
    
    Local $iUBoundTarget0 = UBound($avArrayTarget, 0), $iUBoundSource0 = UBound($avArraySource, 0)
    If $iUBoundTarget0 <> $iUBoundSource0 Then Return SetError(1, 3, -1); 1D/2D dimensionality did not match
    If $iUBoundTarget0 > 2 Then Return SetError(1, 4, -1); At least one array was 3D or more
    
    Local $iUBoundTarget1 = UBound($avArrayTarget, 1), $iUBoundSource1 = UBound($avArraySource, 1)
    
    Local $iNewSize = $iUBoundTarget1 + $iUBoundSource1
    If $iUBoundTarget0 = 1 Then
       ; 1D arrays
        ReDim $avArrayTarget[$iNewSize]
        For $i = 0 To $iUBoundSource1 - 1
            $avArrayTarget[$iUBoundTarget1 + $i] = $avArraySource[$i]
        Next
    Else
       ; 2D arrays
        Local $iUBoundTarget2 = UBound($avArrayTarget, 2), $iUBoundSource2 = UBound($avArraySource, 2)
        If $iUBoundSource2 > $iUBoundTarget2 Then Return SetError(1, 5, -1); 2D boundry of source too large for target
        ReDim $avArrayTarget[$iNewSize][$iUBoundTarget2]
        For $r = 0 To $iUBoundSource1 - 1
            For $c = 0 To $iUBoundSource2 - 1
                $avArrayTarget[$iUBoundTarget1 + $r][$c] = $avArraySource[$r][$c]
            Next
        Next
    EndIf
    
    Return $iNewSize - 1
EndFunc;==>__ArrayConcatenate

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...