Meine Array Funktionen

  • Hier ein paar Array-Funktionen von mir die Beschreibungen schreib ich später. Falls jemand fragen hat soll er die einfach hier stellen.

    Spoiler anzeigen
    [autoit]

    #include-once

    [/autoit] [autoit][/autoit] [autoit]

    ; #INDEX# =======================================================================================================================
    ; Title .........: Extended Array
    ; AutoIt Version : 3.2.10++ (not tested)
    ; Language ......: (Bad) English :=)
    ; Description ...: This module contains some functions to manipulating arrays.
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    ; #NO_DOC_FUNCTION# =============================================================================================================
    ; Not documented - function(s) no longer needed, will be worked out of the file at a later date
    ; ===============================================================================================================================
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    ; #CURRENT# =====================================================================================================================
    ;_ArrayCall
    ;_ArrayDiff
    ;_ArraySum
    ;_ArraySortWith
    ;_ArraySplice
    ;_ArraySlice
    ;_ArrayRand
    ;_ArrayShuffle
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ;__Array_Value_Exists
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _ArrayCall
    ; Description ...: Excutes a function of all items in a 1d and 2d array.
    ; Syntax.........: _ArrayCall(ByRef $avArray, $sFunction)
    ; Parameters ....: $avArray - Array to use
    ; $sFunction - Function to call
    ; Return values .: Success - 1 , sets @extend
    ; | 1 - Used Call
    ; | 2 - Used Execute
    ; Failure - 0, sets @error to
    ; | 1 - $avArray is not an array
    ; | 2 - $sFunction is not a string
    ; | 3 - Call / Excute failed , $sFunction dont exist or parameters were incorect
    ; | 4 - $avArray has more then 2 dimensions
    ; Author ........: Tom Schuster <Tom---Schuster at web dot de>
    ; Modified.......:
    ; Remarks .......:
    ; Related .......: _ArraySortWith , Call , Execute
    ; Link ..........;
    ; Example .......; Yes
    ; ===============================================================================================================================
    func _ArrayCall ( ByRef $avArray, $sFunction )
    if not IsArray ( $avArray ) Then return SetError ( 1, 0, 0
    if not isstring ( $sFunction ) Then return SetError ( 2, 0, 0)

    dim $avTmp[ubound ($avArray)]

    Local $key = "", $methode = 1


    switch ubound ( $avArray, 0 )

    case 1

    for $i = 0 to ubound ( $avArray ) -1

    $avTmp[$i] = Call ( $sFunction , $avArray[$i] )
    if @error then

    $methode = 2
    $avTmp[$i] = Execute ($sFunction & "( $avArray[$i] )")
    if @error then return SetError (3 , @error, 0)
    EndIf

    Next

    [/autoit] [autoit][/autoit] [autoit]

    case 2

    redim $avTmp[UBound ($avArray )][UBound ($avArray,2)]

    for $i = 0 to UBound ( $avArray ) -1

    for $s = 0 to UBound ( $avArray , 2) -1

    $avTmp[$i][$s] = Call ( $sFunction , $avArray[$i][$s] )

    if @error then

    $methode = 2
    $avTmp[$i][$s] = Execute ($sFunction & "( $avArray[$i][$s] )")
    if @error then return SetError (3 , @error, 0)
    EndIf
    Next
    Next

    case Else

    return SetError ( 4, 0 , 0 )

    EndSwitch


    $avArray = $avTmp ;we dont want to damge the wohle array if this function fails
    return SetExtended ( $methode , 1)
    EndFunc ;==>_ArrayCall

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _ArrayDiff
    ; Description ...: Returns an array with values, wich dont exist in $avArray2
    ; Syntax.........: _ArrayDiff(ByRef $avArray, ByRef $avArray2)
    ; Parameters ....: $avArray - Array to check
    ; $avArray2 - Array to use
    ; Return values .: Success - Array with unqiue values
    ; Failure - 0, sets @error to
    ; | 1 - $avArray is not an array
    ; | 2 - $avArray2 is not an array
    ; | 3 - No unqiue value exist
    ; Author ........: Tom Schuster <Tom---Schuster at web dot de>
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........;
    ; Example .......; No
    ; ===============================================================================================================================
    func _ArrayDiff ( ByRef $avArray, ByRef $avArray2 )
    if not IsArray ( $avArray ) then return seterror ( 1 , 0 , 0 )
    if not IsArray ( $avArray2 ) then return seterror ( 2 , 0 , 0 )

    Local $iUbound = UBound ( $avArray ), $x = 0

    dim $avTmp[$iUbound]

    for $i = 0 to $iUbound -1

    if not __Array_Value_Exists ( $avArray2 , $avArray[$i] ) Then
    $avTmp[$x] = $avArray[$i]
    $x += 1
    EndIf
    Next
    if $x = 0 then Return SetError ( 3 ,0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    redim $avTmp[$x]

    return $avTmp
    EndFunc ;==>_ArrayDiff

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _ArraySum
    ; Description ...: Returns all numeric values added
    ; Syntax.........: _ArrayDiff(ByRef $avArray, [$iNumbersAsString])
    ; Parameters ....: $avArray - Array to use
    ; $iNumbersAsString - [optional] Add numerical strings too
    ; Return values .: Success - the result , could be 0 so check for @error
    ; Failure - 0, sets @error to
    ; | 1 - $avArray is not an array
    ; | 2 - No Numbers found
    ; | 3 - $avArray has more then 1 Dimension
    ; Author ........: Tom Schuster <Tom---Schuster at web dot de>
    ; Modified.......:
    ; Remarks .......:
    ; Related .......: IsInt, IsFloat, StringIsFloat, StringIsInt, Number
    ; Link ..........;
    ; Example .......; No
    ; ===============================================================================================================================
    func _ArraySum ( ByReF $avArray , $iNumbersAsString = 0 )

    [/autoit] [autoit][/autoit] [autoit]

    ;check if array
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)
    if ubound ( $avArray , 0) <> 1 then Return SetError ( 3, 0, 0)

    Local $iUbound = ubound ( $avArray ) -1, $fSum = 0, $iNumber = 0


    for $i=0 to $iUbound
    $vTmp = $avArray[$i]

    ;normal check if is integer or float
    if isint ( $vTmp ) or IsFloat ( $vTmp ) Then
    $iNumber = 1 ; means a number was found, so no error code 2
    $fSum += $vTmp ;add them
    else
    ;if use Numbers as datatype "string" and is number vTmp
    if $iNumbersAsString and ( StringIsFloat ( $vTmp ) or StringIsInt ( $vTmp ) ) and isstring ( $vTmp ) Then
    $iNumber = 1
    $fSum += Number ($vTmp) ; convert in a Number
    EndIf

    EndIf

    Next

    ;no numbers in array
    if $iNumber = 0 then SetError ( 2 , 0 , 0)
    return $fSum
    EndFunc ;==>_ArraySum

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _ArraySortWith
    ; Description ...: Sorts an array with a defined Function
    ; Syntax.........: _ArraysSortWith(ByRef $avArray, $sFunction, [$avParameter = 0[, $sFirstValueAlias = "$mFirstValue"[, $sSecondValueAlias = "$mSecondValue"]]])
    ; Parameters ....: $avArray - Array wich will be sorted
    ; $sFunction - Function to use ( must return somthing like -1, 0, +1; like StringCompare)
    ; $avParameter - [optional] Array to use if Paramters must be specifed ( They value with the value of $sFirstValueAlias
    ; will be replaced with the first value for sorting; with $sSecondValueAlias its the same)
    ; $sFirstValueAlias - [optional] A key with this value in $avParameter will be replaced with the first value to compare
    ; $sSecondValueAlias- [optional] The second value to compare
    ;
    ; Return values .: Success - 1, sets @extended to
    ; | 1 - Used Call
    ; | 2 - Used Excute
    ; Failure - 0, sets @error to
    ; | 1 - $avArray is not an array
    ; | 2 - Call and Execute failed
    ; | 3 - The return of $sFunction was incorrect
    ; | 4 - $sFirstValueAlias or $sSecondValueAlias dont exist in the $avParameter array
    ; | 5 - $avArray has more then 1 dimesion
    ; Author ........: Tom Schuster <Tom---Schuster at web dot de>
    ; Modified.......:
    ; Remarks .......:
    ; Related .......: _ArrayCall, _ArraySort, Call, Execute, StringCompare
    ; Link ..........;
    ; Example .......; No
    ; ===============================================================================================================================
    func _ArraySortWith ( ByRef $avArray , $sFunction, $avParameter = 0, $sFirstValueAlias = "$mFirstValue", $sSecondValueAlias = "$mSecondValue")
    ;check if array
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)
    if ubound ( $avArray , 0) <> 1 then Return SetError ( 5, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    Local $iUbound = ubound ( $avArray ) - 1, $c = 0 , $methode = 1, $iFirstValuePos = -1 , $iSecondValuePos = -1 , $sArgString = "", $iUseArgArray = 0

    ;check if parameter
    if isarray ( $avParameter ) Then

    for $i= 0 to ubound ( $avParameter ) -1

    if $avParameter[$i] == $sFirstValueAlias then
    $iFirstValuePos = $i + 1
    EndIf

    if $avParameter[$i] == $sSecondValueAlias then
    $iSecondValuePos = $i + 1
    EndIf
    $sArgString &= "$avArgArray[" & $i +1 & "], "
    Next
    $sArgString = StringTrimRight ($sArgString, 2)

    if $iFirstValuePos == -1 or $iSecondValuePos == -1 then return SetError ( 4 , 0, 0)

    dim $avArgArray[1]
    $avArgArray[0] = "CallArgArray"
    redim $avArgArray[1 + UBound ( $avParameter )]
    for $i = 0 to ubound ($avParameter) -1
    $avArgArray[$i+1] = $avParameter[$i]
    Next

    $iUseArgArray = 1
    EndIf


    for $i = 1 to $iUbound

    $vTmp = $avArray[$i]

    [/autoit] [autoit][/autoit] [autoit]

    for $j = $i -1 to 0 step -1
    $vCur = $avArray[$j]


    if $iUseArgArray Then

    $avArgArray[$iFirstValuePos] = $vTmp
    $avArgArray[$iSecondValuePos] = $vCur

    $c = call ( $sFunction, $avArgArray )

    if @error then

    $methode = 2
    $c = Execute ( $sFunction & "(" & $sArgString & ")" )
    if @error then
    return SetError ( 2 , 0 ,0 )
    EndIf
    EndIf
    Else
    ;try to use call
    $c = call ( $sFunction , $vTmp , $vCur)

    if @error Then
    ; mhm dont work maybe its an built-in AutoIt function or plug-in function (see Call Function Reference) so try with Execute
    $methode = 2
    $c = Execute ( $sFunction & '( "' & $vTmp & '", "' & $vCur & '")' )
    if @error then
    return SetError ( 2 , 0 , 0 ) ;the function really dont exist or dont have enough paramters
    EndIf
    EndIf
    EndIf

    if not isint ( $c ) Then return SetError ( 3 , 0 , 0) ; check if is int and not something else ( the function must return 0 , +1, -1 usw, like StringCompare () )

    if $c >= 0 then ExitLoop
    $avArray[$j + 1] = $vCur
    Next

    $avArray[$j + 1] = $vTmp
    Next

    [/autoit] [autoit][/autoit] [autoit]

    return SetExtended ( $methode , 1 )
    EndFunc ;==>_ArraySortWith

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _ArraySplice
    ; Description ...: Delets a Defined Range of an array
    ; Syntax.........: _ArraySplice(ByRef $avArray, $iStart[, $iEnd=-1])
    ; Parameters ....: $avArray - Array to edit
    ; $iStart - Where to start deleting
    ; $iEnd - [optional] Where to end deliting (default: at end of array)
    ;
    ; Return values .: Success - New array size
    ; Failure - 0, sets @error to
    ; | 1 - $avArray is not an array
    ; | 2 - The array would be the same like before
    ; | 3 - $iStart is greater than $iEnd
    ; | 4 - $avArray has more then 1 dimension
    ;
    ; Author ........: Tom Schuster <Tom---Schuster at web dot de>
    ; Modified.......:
    ; Remarks .......:
    ; Related .......: _ArraySlice
    ; Link ..........;
    ; Example .......; No
    ; ===============================================================================================================================
    func _ArraySplice (ByRef $avArray , $iStart, $iEnd=-1)
    ;check if array
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)
    if ubound ( $avArray , 0) <> 1 then Return SetError ( 4, 0, 0)

    Local $iUbound = UBound ( $avArray ) -1, $s = 0

    ;bound checking
    if $iStart > $iUbound or $iStart < 0 then $iStart = 0
    if $iEnd + 1 > $iUbound or $iEnd < 0 then $iEnd = $iUbound

    [/autoit] [autoit][/autoit] [autoit]

    ;seterror because there wont be any change in the array
    if $iStart == 0 and $iEnd == $iUbound then Return SetError (2, 0, 0)

    ;logic mistake of user ^^
    if $iStart > $iEnd then Return SetError (3, 0, 0)

    $s = $iStart
    for $i = $iEnd +1 to $iUbound

    $avArray[$s] = $avArray[$i]
    $s += 1
    Next

    redim $avArray[$iUbound - ( $iEnd - $iStart )]

    [/autoit] [autoit][/autoit] [autoit]

    Return $iUbound - ( $iEnd - $iStart ) ; return new array size

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_ArraySlice

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _ArraySlice
    ; Description ...: Returns a specified range of an array
    ; Syntax.........: _ArraySlice(ByRef $avArray, $iStart[, $iEnd=-1])
    ; Parameters ....: $avArray - Array to use
    ; $iStart - Where to start
    ; $iEnd - [optional] Where to end (default: at end of array)
    ;
    ; Return values .: Success - The Array
    ; Failure - 0, sets @error to
    ; | 1 - $avArray is not an array
    ; | 2 - $iStart is greater then $iEnd
    ; | 3 - $Start is the same like $iEnd ( idiot: use $avArray[$iStart] or $avArray[$iEnd] )
    ; | 4 - $avArray has more then 1 dimension
    ;
    ; Author ........: Tom Schuster <Tom---Schuster at web dot de>
    ; Modified.......:
    ; Remarks .......:
    ; Related .......: _ArraySplice
    ; Link ..........;
    ; Example .......; No
    ; ===============================================================================================================================
    func _ArraySlice ( ByRef $avArray , $iStart, $iEnd=-1)
    ;check if array
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)
    if ubound ( $avArray , 0) <> 1 then Return SetError ( 4, 0, 0)

    Local $iUbound = UBound ( $avArray ) -1, $iCount = $iUbound, $x = 0

    ;creat $avTemp
    Dim $avTemp[$iUbound]
    ;bounds checking
    if $iStart > $iUbound or $iStart < 0 then $iStart = 0
    if $iEnd > $iUbound or $iEnd < 0 then $iEnd = $iUbound

    ;mhm i love this very clever users
    if $iStart > $iEnd then Return SetError ( 2,0,0 )
    if $iStart == $iEnd then Return SetError ( 3, 0,0 )

    ;easy :)
    if $iStart == 0 and $iEnd = $iUbound then Return $avArray

    $iCount = $iEnd - $iStart


    for $i = $iStart to $iEnd
    $avTemp[$x] = $avArray[$i]
    $x += 1
    Next

    redim $avTemp[$iCount+1]

    return $avTemp ; return slice and dont change avArray for this use _ArraySplice
    EndFunc ;==>_ArraySlice

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _ArrayRand
    ; Description ...: Returns random keys of an array
    ; Syntax.........: _ArrayRand(ByRef $avArray[, $iNum=1])
    ; Parameters ....: $avArray - Array to use
    ; $iNum - Number of random keys if 1 then only a int key will return and not an array
    ;
    ; Return values .: Success - An array with random keys or a integer key.
    ; Failure - 0, sets @error to
    ; | 1 - $avArray is not an array
    ; | 2 - $avArray has more then 1 dimension
    ;
    ; Author ........: Tom Schuster <Tom---Schuster at web dot de>
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........;
    ; Example .......; No
    ; ===============================================================================================================================
    func _ArrayRand ( ByRef $avArray , $iNum = 1)
    ;check if array
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)
    if ubound ( $avArray , 0) <> 1 then Return SetError ( 2, 0, 0)

    Local $iUbound = UBound ( $avArray )

    ; check if iNum is not negative and not more then array size
    if $iNum < 1 then $iNum = 1
    if $iNum > $iUbound then $iNum = $iUbound

    if $iNum == 1 Then
    return random ( 0 , $iUbound , 1 ) ;easy only return a radnom key bewtwen 0 and the max array size ( ubound ( $avArray) -1 )
    Else
    Dim $avNumbers[$iNum] ; creat array to hold the random numbers
    for $i=1 to $iNum
    do
    $iNumber = Random ( 0 , $iUbound-1 , 1 ) ;select random index number
    Until __Array_Value_Exists ( $avNumbers , $iNumber ) == 0 ;check if not allready in $avNumbers
    $avNumbers[$i-1] = $iNumber ; add to array -1, because whe started with $i = 1
    Next
    return $avNumbers ;return array with the random numbers
    EndIf
    EndFunc ;==>_ArrayRand

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _ArrayShuffle
    ; Description ...: Shuffle an Array
    ; Syntax.........: _ArrayShuffle(ByRef $avArray)
    ; Parameters ....: $avArray - Array to use
    ;
    ; Return values .: Success - 1
    ; Failure - 0, sets @error to
    ; | 1 - $avArray is not an array
    ; | 2 - $avArray has more then 1 dimension
    ;
    ; Author ........: Tom Schuster <Tom---Schuster at web dot de>
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........;
    ; Example .......; No
    ; ===============================================================================================================================
    func _ArrayShuffle ( ByRef $avArray )
    ; check if array
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)
    if ubound ( $avArray , 0) <> 1 then Return SetError ( 2, 0, 0)

    $iUbound = UBound ( $avArray )

    ;creat tmp array with double size of $avArray
    dim $avTmp[$iUbound*2]

    $iUboundTemp = UBound ( $avTmp )

    for $i = 0 to $iUbound -1
    Do
    $iNumber = Random ( 0 , $iUboundTemp-1, 1 ) ; creat random key
    Until stringleft ( $avTmp[$iNumber], 1 ) <> chr ( 1 ) ; if $avTmp[$iNumber] is empty (unassigned) Then
    $avTmp[$iNumber] = chr ( 1 ) & $avArray[$i] ;add $avArray[$i] with ascii character 1 , because the $avArray[$i] could be empty
    Next

    $x = 0

    for $i=0 to $iUbound * 2 - 1

    if StringLeft ( $avTmp[$i], 1 ) == chr ( 1 ) Then ; check if not empty
    $avArray[$x] = StringTrimLeft ($avTmp[$i], 1) ;remove leading chr (1)
    $x += 1 ;increment $avArray index to use
    EndIf

    Next

    Return 1
    EndFunc ;==>_ArrayShuffle

    [/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ; Name...........: __Array_Value_Exists
    ;================================================================================================================================
    func __Array_Value_Exists ( ByRef $avArray , $vValue )
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)

    Local $iUbound = UBound ( $avArray ) -1, $iMatchs = 0

    for $i=0 to $iUbound
    if $avArray[$i] == $vValue then
    $iMatchs += 1
    EndIf
    Next

    return $iMatchs
    EndFunc ;==>__Array_Value_Exists

    [/autoit]

    Edit BugFix: AutoIt-Tags gesetzt

    2 Mal editiert, zuletzt von Tom99 (17. August 2008 um 00:29)

  • Hallo,
    zu den Funktionen kann ich nichts sagen, erstmal hab ich die noch net ausprobiert und zudem ist mir auch nicht ganz ersichtlich was diese tun ;) Mir sind aber zwei Dinge aufgefallen: 1. Vergleiche von Werten benötigen in AutoIt nur ein einfaches Gleichheitszeichen, zwei werden nur benötigt um bei Strings die Groß- und Kleinschreibung zu beachten. 2. Wofür hast du immer ein ByRef in den Funktions äh *Wort such* beschreibungen? Ich kann keinen Nutzen erkennen. :huh:
    Aber sonst: Schön das sich noch jemand außer BugFix um Arrays kümmert :thumbup:

    Projekte: Keine größeren (und fertigen)
    Gegen Internetzensur:
    https://epetitionen.bundestag.de/index.php?acti…s;petition=3860
    (Zeichnungsfrist abgelaufen)
    __________________________________________________________________________________________________________________________________
    Dieser Beitrag wurde bereits 264 mal editiert, zuletzt von »Fast2« (30. Februar 2009, 12:99)

  • 1. Mach ich so weil ich normalerweise PHP programmiere.
    2. Was ?! Meinst du das ";check if array", wenn ja das hab ich einfach immer kopiert ^^

    Danke :)
    Ich finds nur schade das es in Autoit keine Assoziatives Arrays gibt :(

    • Offizieller Beitrag

    Wird sowas auch mal in AutoIt Core gamcht?


    Hätte ich nichts dagegen, aber ob Jos das auf seiner Liste hat... :S
    Wie sagte Asterix so schön: Die sind komisch, die Briten. :D
    (OK, er sagte 'spinnen' - aber ich wollte nicht so böse sein ;) )

  • ^.° :rock:
    Gibts nicht so eine Liste was kommt und was nicht ?
    Ok auf der NotOnToDoList es ist es nicht

    Einmal editiert, zuletzt von Tom99 (17. August 2008 um 12:08)

    • Offizieller Beitrag

    Hi,

    ich habe auch noch eine kleine Änderung an einer Funktion gemacht, weil es mich gestört hat bei DBs, dass die Spaltenüberschriften nicht zu sehen waren.

    Spoiler anzeigen
    [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _ArrayDisplay
    ; Description ...: Displays given 1D or 2D array array in a listview.
    ; Syntax.........: _ArrayDisplay(Const ByRef $avArray[, $sTitle = "Array: ListView Display"[, $iItemLimit = -1[, $iTranspose = 0[, $sSeparator = ""[, $sReplace = "|"]]]]])
    ; Parameters ....: $avArray - Array to display
    ; $sTitle - [optional] Title to use for window
    ; $iItemLimit - [optional] Maximum number of listview items (rows) to show
    ; $iTranspose - [optional] If set differently than default, will transpose the array if 2D
    ; $sSeparator - [optional] Change Opt("GUIDataSeparatorChar") on-the-fly
    ; $sReplace - [optional] String to replace any occurrence of $sSeparator with in each array element
    ; Return values .: Success - 1
    ; Failure - 0, sets @error:
    ; |1 - $avArray is not an array
    ; |2 - $avArray has too many dimensions (only up to 2D supported)
    ; |3 - $header_A is not an array
    ; Author ........: randallc, Ultima
    ; Modified.......: Gary Frost (gafrost) / Ultima: modified to be self-contained (no longer depends on "GUIListView.au3") / Xenobiologist header
    ; Remarks .......:
    ; Related .......:
    ; Link ..........;
    ; Example .......; Yes
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    Global $database_A[2][2] = [['www.Autoitscript.com', 'English forum'],['www.autoit.de', 'German forum']]
    Global $header_A[2] = ['URL', 'Description']

    [/autoit] [autoit][/autoit] [autoit]

    Global $digtis_A[5] = [1, 2, 3, 4, 5]
    Global $header1_A[1] = ['Digits']

    [/autoit] [autoit][/autoit] [autoit]

    _ArrayDisplay_WithHeader($database_A, $header_A)
    ;~ _ArrayDisplay_WithHeader($digtis_A, $header1_A)
    _ArrayDisplay_WithHeader($digtis_A, -1, "Titel")

    [/autoit] [autoit][/autoit] [autoit]

    Func _ArrayDisplay_WithHeader(Const ByRef $avArray, $header_A = -1, $sTitle = "Array: ListView Display", $iItemLimit = -1, $iTranspose = 0, $sSeparator = "", $sReplace = "|")
    If Not IsArray($avArray) Then Return SetError(1, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ; Dimension checking
    Local $iDimension = UBound($avArray, 0), $iUBound = UBound($avArray, 1) - 1, $iSubMax = UBound($avArray, 2) - 1
    If $iDimension > 2 Then Return SetError(2, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ; Separator handling
    ;~ If $sSeparator = "" Then $sSeparator = Chr(1)
    If $sSeparator = "" Then $sSeparator = Chr(124)

    [/autoit] [autoit][/autoit] [autoit]

    ; Declare variables
    Local $i, $j, $vTmp, $aItem, $avArrayText, $sHeader = "Row", $iBuffer = 64
    Local $iColLimit = 250, $iLVIAddUDFThreshold = 4000, $iWidth = 640, $iHeight = 480
    Local $iOnEventMode = Opt("GUIOnEventMode", 0), $sDataSeparatorChar = Opt("GUIDataSeparatorChar", $sSeparator)

    [/autoit] [autoit][/autoit] [autoit]

    ; Swap dimensions if transposing
    If $iSubMax < 0 Then $iSubMax = 0
    If $iTranspose Then
    $vTmp = $iUBound
    $iUBound = $iSubMax
    $iSubMax = $vTmp
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Set limits for dimensions
    If $iSubMax > $iColLimit Then $iSubMax = $iColLimit
    If $iItemLimit = 1 Then $iItemLimit = $iLVIAddUDFThreshold
    If $iItemLimit < 1 Then $iItemLimit = $iUBound
    If $iUBound > $iItemLimit Then $iUBound = $iItemLimit
    If $iLVIAddUDFThreshold > $iUBound Then $iLVIAddUDFThreshold = $iUBound

    If Not IsArray($header_A) Or $header_A = -1 Then
    ; Set header up
    For $i = 0 To $iSubMax
    $sHeader &= $sSeparator & "Col " & $i
    Next
    Else
    ; Set header up
    For $i = 0 To UBound($header_A) - 1
    $sHeader &= $sSeparator & $header_A[$i]
    Next
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Convert array into text for listview
    Local $avArrayText[$iUBound + 1]
    For $i = 0 To $iUBound
    $avArrayText[$i] = "[" & $i & "]"
    For $j = 0 To $iSubMax
    ; Get current item
    If $iDimension = 1 Then
    If $iTranspose Then
    $vTmp = $avArray[$j]
    Else
    $vTmp = $avArray[$i]
    EndIf
    Else
    If $iTranspose Then
    $vTmp = $avArray[$j][$i]
    Else
    $vTmp = $avArray[$i][$j]
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Add to text array
    $vTmp = StringReplace($vTmp, $sSeparator, $sReplace, 0, 1)
    $avArrayText[$i] &= $sSeparator & $vTmp

    [/autoit] [autoit][/autoit] [autoit]

    ; Set max buffer size
    $vTmp = StringLen($vTmp)
    If $vTmp > $iBuffer Then $iBuffer = $vTmp
    Next
    Next
    $iBuffer += 1

    [/autoit] [autoit][/autoit] [autoit]

    ; GUI Constants
    Local Const $_ARRAYCONSTANT_GUI_DOCKBORDERS = 0x66
    Local Const $_ARRAYCONSTANT_GUI_DOCKBOTTOM = 0x40
    Local Const $_ARRAYCONSTANT_GUI_DOCKHEIGHT = 0x0200
    Local Const $_ARRAYCONSTANT_GUI_DOCKLEFT = 0x2
    Local Const $_ARRAYCONSTANT_GUI_DOCKRIGHT = 0x4
    Local Const $_ARRAYCONSTANT_GUI_EVENT_CLOSE = -3
    Local Const $_ARRAYCONSTANT_LVIF_PARAM = 0x4
    Local Const $_ARRAYCONSTANT_LVIF_TEXT = 0x1
    Local Const $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH = (0x1000 + 29)
    Local Const $_ARRAYCONSTANT_LVM_GETITEMCOUNT = (0x1000 + 4)
    Local Const $_ARRAYCONSTANT_LVM_GETITEMSTATE = (0x1000 + 44)
    Local Const $_ARRAYCONSTANT_LVM_INSERTITEMA = (0x1000 + 7)
    Local Const $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE = (0x1000 + 54)
    Local Const $_ARRAYCONSTANT_LVM_SETITEMA = (0x1000 + 6)
    Local Const $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT = 0x20
    Local Const $_ARRAYCONSTANT_LVS_EX_GRIDLINES = 0x1
    Local Const $_ARRAYCONSTANT_LVS_SHOWSELALWAYS = 0x8
    Local Const $_ARRAYCONSTANT_WS_EX_CLIENTEDGE = 0x0200
    Local Const $_ARRAYCONSTANT_WS_MAXIMIZEBOX = 0x00010000
    Local Const $_ARRAYCONSTANT_WS_MINIMIZEBOX = 0x00020000
    Local Const $_ARRAYCONSTANT_WS_SIZEBOX = 0x00040000
    Local Const $_ARRAYCONSTANT_tagLVITEM = "int Mask;int Item;int SubItem;int State;int StateMask;ptr Text;int TextMax;int Image;int Param;int Indent;int GroupID;int Columns;ptr pColumns"

    [/autoit] [autoit][/autoit] [autoit]

    Local $iAddMask = BitOR($_ARRAYCONSTANT_LVIF_TEXT, $_ARRAYCONSTANT_LVIF_PARAM)
    Local $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]"), $pBuffer = DllStructGetPtr($tBuffer)
    Local $tItem = DllStructCreate($_ARRAYCONSTANT_tagLVITEM), $pItem = DllStructGetPtr($tItem)
    DllStructSetData($tItem, "Param", 0)
    DllStructSetData($tItem, "Text", $pBuffer)
    DllStructSetData($tItem, "TextMax", $iBuffer)

    [/autoit] [autoit][/autoit] [autoit]

    ; Set interface up
    Local $hGUI = GUICreate($sTitle, $iWidth, $iHeight, 10, 10, BitOR($_ARRAYCONSTANT_WS_SIZEBOX, $_ARRAYCONSTANT_WS_MINIMIZEBOX, $_ARRAYCONSTANT_WS_MAXIMIZEBOX))
    Local $aiGUISize = WinGetClientSize($hGUI)
    Local $hListView = GUICtrlCreateListView($sHeader, 0, 0, $aiGUISize[0], $aiGUISize[1] - 26, $_ARRAYCONSTANT_LVS_SHOWSELALWAYS)
    Local $hCopy = GUICtrlCreateButton("Copy Selected", 3, $aiGUISize[1] - 23, $aiGUISize[0] - 6, 20)
    GUICtrlSetResizing($hListView, $_ARRAYCONSTANT_GUI_DOCKBORDERS)
    GUICtrlSetResizing($hCopy, $_ARRAYCONSTANT_GUI_DOCKLEFT + $_ARRAYCONSTANT_GUI_DOCKRIGHT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT)
    GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_GRIDLINES, $_ARRAYCONSTANT_LVS_EX_GRIDLINES)
    GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT)
    GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE)

    [/autoit] [autoit][/autoit] [autoit]

    ; Fill listview
    For $i = 0 To $iLVIAddUDFThreshold
    GUICtrlCreateListViewItem($avArrayText[$i], $hListView)
    Next
    For $i = ($iLVIAddUDFThreshold + 1) To $iUBound
    $aItem = StringSplit($avArrayText[$i], $sSeparator)
    DllStructSetData($tBuffer, "Text", $aItem[1])

    [/autoit] [autoit][/autoit] [autoit]

    ; Add listview item
    DllStructSetData($tItem, "Item", $i)
    DllStructSetData($tItem, "SubItem", 0)
    DllStructSetData($tItem, "Mask", $iAddMask)
    GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_INSERTITEMA, 0, $pItem)

    [/autoit] [autoit][/autoit] [autoit]

    ; Set listview subitem text
    DllStructSetData($tItem, "Mask", $_ARRAYCONSTANT_LVIF_TEXT)
    For $j = 2 To $aItem[0]
    DllStructSetData($tBuffer, "Text", $aItem[$j])
    DllStructSetData($tItem, "SubItem", $j - 1)
    GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETITEMA, 0, $pItem)
    Next
    Next

    ; ajust window width
    $iWidth = 0
    For $i = 0 To $iSubMax + 1
    $iWidth += GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH, $i, 0)
    Next
    If $iWidth < 250 Then $iWidth = 230
    WinMove($hGUI, "", Default, Default, $iWidth + 20)

    [/autoit] [autoit][/autoit] [autoit]

    ; Show dialog
    GUISetState(@SW_SHOW, $hGUI)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Switch GUIGetMsg()
    Case $_ARRAYCONSTANT_GUI_EVENT_CLOSE
    ExitLoop

    [/autoit] [autoit][/autoit] [autoit]

    Case $hCopy
    Local $sClip = ""

    [/autoit] [autoit][/autoit] [autoit]

    ; Get selected indices [ _GUICtrlListView_GetSelectedIndices($hListView, True) ]
    Local $aiCurItems[1] = [0]
    For $i = 0 To GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETITEMCOUNT, 0, 0)
    If GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETITEMSTATE, $i, 0x2) Then
    $aiCurItems[0] += 1
    ReDim $aiCurItems[$aiCurItems[0] + 1]
    $aiCurItems[$aiCurItems[0]] = $i
    EndIf
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ; Generate clipboard text
    If Not $aiCurItems[0] Then
    For $sItem In $avArrayText
    $sClip &= $sItem & @CRLF
    Next
    Else
    For $i = 1 To UBound($aiCurItems) - 1
    $sClip &= $avArrayText[$aiCurItems[$i]] & @CRLF
    Next
    EndIf
    ClipPut($sClip)
    EndSwitch
    WEnd
    GUIDelete($hGUI)

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", $iOnEventMode)
    Opt("GUIDataSeparatorChar", $sDataSeparatorChar)

    [/autoit] [autoit][/autoit] [autoit]

    Return 1
    EndFunc ;==>_ArrayDisplay_WithHeader

    [/autoit]

    Mega