Jump to content
Sign in to follow this  
Tolf

Array2D.au3 UDF

Recommended Posts

Tolf

I've updated the UDF "Array.au3" that is included in AutoIt to be able to work on 2D arrays.

Here is an example of what my UDF can do :

#include <Array2D.au3>
Dim $avArray[8][2]
$avArray[0][0] = "JPM 0"
$avArray[1][0] = "Holger 1"
$avArray[2][0] = "Larry 3"
$avArray[3][0] = "Jeremy 4"
$avArray[4][0] = "Valik 5"
$avArray[5][0] = "Cyberslug 6"
$avArray[6][0] = "Nutster 7"
$avArray[7][0] = "JdeB 8"

$avArray[0][1] = "Andrew"
$avArray[1][1] = "Bill"
$avArray[2][1] = "David"
$avArray[3][1] = "Elisabeth"
$avArray[4][1] = "Frederick"
$avArray[5][1] = "George"
$avArray[6][1] = "Harry"
$avArray[7][1] = "Isabel"

_Array2D_SetDelim(",")
    _Array2D_Display($avArray, "Whole array")
_Array2D_Add($avArray, "Tylo 9,John")
    _Array2D_Display($avArray, "Added 1D-array")
_Array2D_Insert($avArray, 2, "Jon 2,Chris")
    _Array2D_Display($avArray, "Inserted 1D-array")
_Array2D_Push($avArray, "JPM 0,Andrew")
    _Array2D_Display($avArray, "Pushed 1D-array")
    _Array2D_Display($avArray, "Titles changed", "Pseudonym,Name")

List of functions

Added functions/parameters

_Array2D_Add (ByRef $avArray, $vValue, $iDim = 1, $iSubItem = 0, $iDoubleRedim = 0)

_Array2D_BinarySearch (Const ByRef $avArray, $vValue, $iStart = 0, $iEnd = -1, $iDim = 1, $iSubItem = 0)

_Array2D_Clear (ByRef $avArray, $iStart = 0, $iEnd = -1, $iDim = 1)

_Array2D_Delete (ByRef $avArray, $iElement, $iDim = 1)

_Array2D_Display (Const ByRef $avArray, $sTitle = "Array: ListView Display", $avCol = "", $avLines = "", $iItemLimit = -1, $iTranspose = 0, $sSeparator = "", $sReplace = "|")

_Array2D_FindAll (Const ByRef $avArray, $vValue, $iStart = 0, $iEnd = -1, $iCase = 0, $iPartial = 0, $iSubItem = 0, $iDim = 1)

_Array2D_From1D (ByRef $avArray, $iTranspose = 0)

_Array2D_FromString ($svString, $sDelimMainDim = "", $sSubDelim = "", $iDim = 1)

_Array2D_Insert (ByRef $avArray, $iElement, $vValue = "", $iDim = 1, $iSubItem = 0, $iDoubleRedim = 0)

_Array2D_Max (Const ByRef $avArray, $iCompNumeric = 0, $iStart = 0, $iEnd = -1, $iDim = 1, $iSubItem = 0)

_Array2D_MaxIndex (Const ByRef $avArray, $iCompNumeric = 0, $iStart = 0, $iEnd = -1, $iDim = 1, $iSubItem = 0)

_Array2D_Min (Const ByRef $avArray, $iCompNumeric = 0, $iStart = 0, $iEnd = -1, $iDim = 1, $iSubItem = 0)

_Array2D_MinIndex (Const ByRef $avArray, $iCompNumeric = 0, $iStart = 0, $iEnd = -1, $iDim = 1, $iSubItem = 0)

_Array2D_StringOperation (ByRef $avArray, $sOperation, $sOperationParam = "", $iStart = 0, $iEnd = -1, $iSubStart = 0, $iSubEnd = -1)

_Array2D_Pop (ByRef $avArray, $iDim = 1)

_Array2D_Push (ByRef $avArray, $vValue, $iDirection = 0, $iDim = 1, $iSynchronize = 1, $iSubItem = 0)

_Array2D_PutValue (ByRef $avArray, $vValue, $iElement = 0, $iDim = 1, $iSubItem = 0)

_Array2D_RandomMix (ByRef $avArray, $iStart = 0, $iEnd = -1, $iDim = 1, $iSynchronize = 1, $iSubItem = 0)

_Array2D_Reverse (ByRef $avArray, $iStart = 0, $iEnd = -1, $iDim = 1)

_Array2D_Search (Const ByRef $avArray, $vValue, $iStart = 0, $iEnd = -1, $iCase = 0, $iPartial = 0, $iForward = 1, $iSubItem = 0, $iDim = 1)

_Array2D_SetDelim ($sDelim = "", $iSplitFlag = 0)

_Array2D_Shift (ByRef $avArray, $iDirection = 1, $iStart = 0, $iEnd = -1, $iDim = 1, $iSize = 1)

_Array2D_Sort (ByRef $avArray, $iDescending = 0, $iStart = 0, $iEnd = -1, $iSubItem = 0, $iDim = 1, $iSynchronize = 1)

_Array2D_Swap (ByRef $vItem1, ByRef $vItem2)

_Array2D_SwapByIndex (ByRef $avArray, $iItem1, $iItem2, $iDim = 1)

_Array2D_ToClip (Const ByRef $avArray, $sDelim = @CR, $iStart = 0, $iEnd = -1, $iDim = 1, $sSubDelim = @TAB, $iSubStart = 0, $iSubEnd = -1)

_Array2D_ToConsole (Const ByRef $avArray, $sDelim = @LF, $iStart = 0, $iEnd = -1, $iDim = 1, $sSubDelim = @TAB, $iSubStart = 0, $iSubEnd = -1)

_Array2D_ToString (Const ByRef $avArray, $sDelim = "|", $iStart = 0, $iEnd = -1, $iDim = 1, $sSubDelim = "", $iSubStart = 0, $iSubEnd = -1)

_Array2D_Transpose (ByRef $avArray)

You can notice that _Array2D_Concatenate and _Array2D_Trim aren't in this list : use respectively _Array2D_Add and _Array2D_StringOperation (for those who still want to use them, they are in the file)

Changelog :

- $avCol and $avLines added to _Array2D_Display (Sep 21 2008)

- _Array2D_SetDelim added (Oct 19 2008)

You will find here the UDF and an example for each function :

Array2D.zip

Previous number of downloads : 47

Your comments, suggestions are welcomed !

Edited by Tolf

My UDF : Array2D

Share this post


Link to post
Share on other sites
Malkey

I've updated the UDF "Array.au3" that is included in AutoIt to be able to work on 2D arrays.

You can notice that _Array2D_Concatenate and _Array2D_Trim aren't in this list : use respectively _Array2D_Add and _Array2D_StringOperation (for those who still want to use them, they are in the file)

You will find here the UDF and an example for each function :

The latest version and beta version of AutoIt do not have an underscore in front of _StringSplit(). It produces an undefined function error from the Array2D.au3 include file. With search and replace. it is an easy fix.

Other than that , it works fine and is nicely presented. I will keep them handy for use when the need arises.

Thank-you for sharing.

Share this post


Link to post
Share on other sites
wraithdu

Nice UDF! I'm curious, what's the difference with your _Array2D_Display, and the original _ArrayDisplay function?

Share this post


Link to post
Share on other sites
Tolf

Nice UDF! I'm curious, what's the difference with your _Array2D_Display, and the original _ArrayDisplay function?

I haven't changed anything excepted that you can use the 'Default' keyword as parameter (Default keyword is supported by all my functions).

My UDF : Array2D

Share this post


Link to post
Share on other sites
Tolf

The latest version and beta version of AutoIt do not have an underscore in front of _StringSplit(). It produces an undefined function error from the Array2D.au3 include file. With search and replace. it is an easy fix.

Other than that , it works fine and is nicely presented. I will keep them handy for use when the need arises.

Thank-you for sharing.

I've the latest version of AutoIt (v3.2.12.1) and _StringSplit from the UDF "String.au3" has an underscore (StringSplit without an underscore is not an UDF). Edited by Tolf

My UDF : Array2D

Share this post


Link to post
Share on other sites
sulfurious

Nice work. I have made my array udf's more dynamic all the time. Here is an arrayadd that I made that is pretty good, maybe to give you some food for thought.

Func _ArrayAddx(ByRef $avArray,$vCounter = False,$iCol = 1,$sV1='',$sV2='',$sV3='',$sV4='',$sV5='',$sV6='',$sV7='',$sV8='',$sV9='',$sV10='')
    
    If $iCol > 10 Then Return SetError(1, 0, -1); keep col count matching parms
    
    If IsArray($avArray) Then
        Local $iUBound = UBound($avArray)
        If $iCol = 1 Then; single dimension
            ReDim $avArray[$iUBound + 1]
            If $vCOUNTER Then $avArray[0] = $iUBound
            $avArray[$iUBound - 1] = $sV1
            Return SetError(0,0,1)
        ElseIf $iCol > 1 Then; multi dimension
            ReDim $avArray[$iUBound + 1][$iCol]
            If $vCOUNTER Then $avArray[0][0] =  $iUBound
            For $i = 1 To $iCol
                $avArray[$iUBound ][$i - 1] = Eval('sV' & $i)
            Next
            Return SetError(0, 0, 1)
        EndIf       
    Else
        Return SetError(1, 0, -1)
    EndIf
EndFunc

Sul

Share this post


Link to post
Share on other sites
Malkey

I've the latest version of AutoIt (v3.2.12.1) and _StringSplit from the UDF "String.au3" has an underscore (StringSplit without an underscore is not an UDF).

You are absolutely correct. I apologies for my misleading information.

It was only the beta version that produced the undefined function.error on _StringSplit.

I found the reason here :- http://www.autoitscript.com/forum/index.ph...hl=_StringSplit

Sorry :)

Share this post


Link to post
Share on other sites
Tolf

I haven't changed anything excepted that you can use the 'Default' keyword as parameter (Default keyword is supported by all my functions).

I've now added the options $avCol and $avLines which enable you to change the names of columns and rows. Be careful because I've put these options before $iItemLimit Edited by Tolf

My UDF : Array2D

Share this post


Link to post
Share on other sites
Tolf

Nice work. I have made my array udf's more dynamic all the time. Here is an arrayadd that I made that is pretty good, maybe to give you some food for thought.

Func _ArrayAddx(ByRef $avArray,$vCounter = False,$iCol = 1,$sV1='',$sV2='',$sV3='',$sV4='',$sV5='',$sV6='',$sV7='',$sV8='',$sV9='',$sV10='')
    
    If $iCol > 10 Then Return SetError(1, 0, -1); keep col count matching parms
    
    If IsArray($avArray) Then
        Local $iUBound = UBound($avArray)
        If $iCol = 1 Then; single dimension
            ReDim $avArray[$iUBound + 1]
            If $vCOUNTER Then $avArray[0] = $iUBound
            $avArray[$iUBound - 1] = $sV1
            Return SetError(0,0,1)
        ElseIf $iCol > 1 Then; multi dimension
            ReDim $avArray[$iUBound + 1][$iCol]
            If $vCOUNTER Then $avArray[0][0] =  $iUBound
            For $i = 1 To $iCol
                $avArray[$iUBound ][$i - 1] = Eval('sV' & $i)
            Next
            Return SetError(0, 0, 1)
        EndIf       
    Else
        Return SetError(1, 0, -1)
    EndIf
EndFunc

Sul

I've added the function _Array2D_SetDelim which allows you to set the values to add (or insert, push,...) using a string with delimiters instead of an array :

#include <Array2D.au3>
Dim $avArray[8][2]
$avArray[0][0] = "JPM 0"
$avArray[1][0] = "Holger 1"
$avArray[2][0] = "Larry 3"
$avArray[3][0] = "Jeremy 4"
$avArray[4][0] = "Valik 5"
$avArray[5][0] = "Cyberslug 6"
$avArray[6][0] = "Nutster 7"
$avArray[7][0] = "JdeB 8"

$avArray[0][1] = "Andrew"
$avArray[1][1] = "Bill"
$avArray[2][1] = "David"
$avArray[3][1] = "Elisabeth"
$avArray[4][1] = "Frederick"
$avArray[5][1] = "George"
$avArray[6][1] = "Harry"
$avArray[7][1] = "Isabel"

_Array2D_SetDelim(",")
    _Array2D_Display($avArray, "Whole array")
_Array2D_Add($avArray, "Tylo 9,John")
    _Array2D_Display($avArray, "Added 1D-array")
_Array2D_Insert($avArray, 2, "Jon 2,Chris")
    _Array2D_Display($avArray, "Inserted 1D-array")
_Array2D_Push($avArray, "JPM 0,Andrew")
    _Array2D_Display($avArray, "Pushed 1D-array")
    _Array2D_Display($avArray, "Titles changed", "Pseudonym,Name")
Edited by Tolf

My UDF : Array2D

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  

×