Snippets ( AutoIt Array ): Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
Line 668: Line 668:
EndIf
EndIf


Func _IsInBounds(ByRef $aArray, $iIndex)
Func _IsInBounds(ByRef Const $aArray, $iIndex)
Local $iDim = UBound($aArray, 0)
Local $iDim = UBound($aArray, 0)
If $iDim < 0 Or $iDim > 2 Then ; If not a 1D or 2D Array, then return -1 and set @error to non-zero.
If $iDim < 0 Or $iDim > 2 Then ; If not a 1D or 2D Array, then return -1 and set @error to non-zero.
Return SetError(1, 0, -1)
Return SetError(1, 0, False)
EndIf
EndIf
Return $iIndex < UBound($aArray, 1)
Return $iIndex < UBound($aArray, 1)

Revision as of 14:52, 28 January 2013


Please always credit an author in your script if you use their code. It is only polite.


_1Dto2DArray

Author: guinness








#include <Array.au3>

Global $aArray_1D[2] = ["Data", "Data"]
_ArrayDisplay($aArray_1D)
_1Dto2DArray($aArray_1D)
_ArrayDisplay($aArray_1D)

Global $aArray_1D[10] = ["Data", "Data", "Data", "Data", "Data", "Data", "Data", "Data", "Data", "Data"]
_ArrayDisplay($aArray_1D)
_1Dto2DArray($aArray_1D, 9)
_ArrayDisplay($aArray_1D)

Func _1Dto2DArray(ByRef $aArray, Const $iAdditionalColumns = 1)
    Local Const $iSize = UBound($aArray, 1)

    Local $aReturn[$iSize][$iAdditionalColumns + 1]

    For $A = 0 To $iSize - 1
        $aReturn[$A][0] = $aArray[$A]
    Next

    $aArray = $aReturn

    Return $aReturn
EndFunc   ;==>_1Dto2DArray

ReturnToContents

_ArrayAddEx

Author: guinness








#include <Array.au3>

Example_1()
Example_2()

Func Example_1()
    Local $aArray_1[1] = ["Data_0"], $iBegin

    $iBegin = TimerInit() ; Start the timer.
    For $i = 1 To 5000
        _ArrayAdd($aArray_1, "Data_" & $i)
    Next
    $iBegin = TimerDiff($iBegin) ; End the timer and find the difference from start to finish.
    ConsoleWrite("_ArrayAdd from Array.au3 >> " & $iBegin & @CRLF)
    _ArrayDisplay($aArray_1)
EndFunc   ;==>Example_1

Func Example_2()
    Local $aArray_2[1] = ["Data_0"], $iBegin, $iDimension, $iCount

    $iBegin = TimerInit() ; Start the timer.
    For $i = 1 To 5000
        _ArrayAddEx($aArray_2, "Data_" & $i, $iDimension, $iCount) ; $iDimension is the overall size of the array & $iCount is the last index number, because regarding the overall size +1 as the next item will give false results as we're increasing the size of the array not by 1 but multiplying 2.
    Next
    $iBegin = TimerDiff($iBegin) ; End the timer and find the difference from start to finish.
    ConsoleWrite("_ArrayAddEx by guinness >> " & $iBegin & @CRLF)
    ReDim $aArray_2[$iCount] ; Remove the empty rows.
    _ArrayDisplay($aArray_2)
EndFunc   ;==>Example_2

Func _ArrayAddEx(ByRef $aArray, $sData, ByRef $iDimension, ByRef $iCount) ; Taken from Array.au3 and modified by guinness to reduce the use of ReDim.
    If IsArray($aArray) = 0 Then
        Return SetError(1, 0, -1)
    EndIf

    If UBound($aArray, 0) <> 1 Then
        Return SetError(2, 0, -1)
    EndIf

    If $iCount = 0 Then
        $iCount = UBound($aArray, 1)
    EndIf

    $iCount += 1
    If ($iCount + 1) >= $iDimension Then
        $iDimension = (UBound($aArray, 1) + 1) * 2
        ReDim $aArray[$iDimension]
    EndIf
    $aArray[$iCount - 1] = $sData
    Return $iCount - 1
EndFunc   ;==>_ArrayAddEx

ReturnToContents

_ArrayEmpty

Author: guinness







Creates Empty 1D & 2D Array's


#include <Array.au3>

Global $aMain[11] = [10]
_ArrayEmpty($aMain)
_ArrayDisplay($aMain, "Empty 1D Array.")

Global $aMainEx[11][3] = [[10]]
_ArrayEmpty($aMainEx)
_ArrayDisplay($aMainEx, "Empty 2D Array.")

Func _ArrayEmpty(ByRef $aArray)
    Switch UBound($aArray, 0) ; Dimension, 1D or 2D array are supported.
        Case 1
            Local $aEmpty1D[1]
            $aArray = $aEmpty1D

        Case 2
            Local $aEmpty2D[1][UBound($aArray, 2)]
            $aArray = $aEmpty2D
    EndSwitch
EndFunc   ;==>_ArrayEmpty

ReturnToContents

_ArrayGet

Author: ProgAndy







Easy access for nested arrays up to 20 nested dimensions (including multidimensional arrays)


Global $b[2] = ["a", "b"]
Global $a[3][2] = [[0, -1], [$b, "x"], [1, -2]]

Global $c[5] = [11, 22, 33, 44, 55]

MsgBox(0, "", _ArrayGet($a, 1, 0, 1) & " # " & @error)

; #FUNCTION# ====================================================================================================================
; Name ..........: _ArrayGet
; Description ...: Gets a value from a nested multidimensional array
; Syntax ........: _ArrayGet(Byref $aArray, $i1[, $i2 = 0[, $i3 = 0[, $i4 = 0[, $i5 = 0[, $i6 = 0[, $i7 = 0[, $i8 = 0[,
;                 $i9 = 0[, $i10 = 0[, $i11 = 0[, $i12 = 0[, $i13 = 0[, $i14 = 0[, $i15 = 0[, $i16 = 0[, $i17 = 0[,
;                 $i18 = 0[, $i19 = 0[, $i20 = 0]]]]]]]]]]]]]]]]]]])
; Parameters ....: $aArray            - [in/out] An array of unknowns.
;                 $i1                 - first array index.
;                 $i2                 - [optional] second array index.
;                 $i3                 - [optional] third array index.
;                 $i4                 - [optional] fourth array index.
;                 $i5                 - [optional] fifth array index.
;                 $i6                 - [optional] sixth array index.
;                 $i7                 - [optional] seventh array index.
;                 $i8                 - [optional] eighth array index.
;                 $i9                 - [optional] ninth array index.
;                 $i10               - [optional] 10th array index.
;                 $i11               - [optional] 11th array index.
;                 $i12               - [optional] 12th array index.
;                 $i13               - [optional] 13th array index.
;                 $i14               - [optional] 14th array index.
;                 $i15               - [optional] 15th array index.
;                 $i16               - [optional] 16th array index.
;                 $i17               - [optional] 17th array index.
;                 $i18               - [optional] 18th array index.
;                 $i19               - [optional] 19th array index.
;                 $i20               - [optional] 20th array index.
; Return values .: Success: Value at the specified index
;                 Error: Nothing, Sets @error to:
;                 |1 - Trying to acces non-array as array
;                 |2 - Not enough dimensions for the last accessed array
;                 |3 - Index out of bounds for a dimension
;                 @extended contains the dimension in error (according to parameter list)
; Author ........: ProgAndy
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _ArrayGet(ByRef $aArray, $i1, $i2=0, $i3=0, $i4=0, $i5=0, $i6=0, $i7=0, $i8=0, $i9=0, $i10=0, $i11=0, $i12=0, $i13=0, $i14=0, $i15=0, $i16=0, $i17=0, $i18=0, $i19=0, $i20=0)
	#forceref $i1, $i2, $i3, $i4, $i5, $i6, $i7, $i8, $i9, $i10, $i11, $i12, $i13, $i14, $i15, $i16, $i17, $i18, $i19, $i20
   ; ProgAndy
    Local $NULL
    If Not IsArray($aArray) Then Return SetError(1, 1, $NULL)
    Local $iDims = UBound($aArray, 0)
    If @NumParams <= $iDims Then Return SetError(2, @NumParams, $NULL)
    Local $sAccess = "$aArray"
    For $i = 1 To $iDims
        Local $iIndex = Int(Eval("i" & $i))
        If $iIndex >= UBound($aArray, $i) Then Return SetError(3, $i, $NULL)
        $sAccess &= '[' & $iIndex & ']'
    Next
    If @NumParams-1 > $iDims Then ; Still indices left
        For $i = $iDims+1 To @NumParams-1
            $sAccess &= ", $i" & $i
        Next
        Local $vResult = Execute("_ArrayGet(" & $sAccess & ")")
        If @error Then SetError(@error, @extended+$iDims)
        Return $vResult
    Else ;
        Return Execute($sAccess)
    EndIf
EndFunc

ReturnToContents

_ArraySet

Author: ProgAndy







Easy access for nested arrays up to 20 nested dimensions (including multidimensional arrays)


Global $b[2] = ['a', 'b'
Global $a[3][2] = [[0, -1], [$b, "x"], [1, -2]]

Global $c[5] = [11, 22, 33, 44, 55]

_ArraySet($a, $c, 1, 0, 0)

; #FUNCTION# ====================================================================================================================
; Name ..........: _ArraySet
; Description ...: Sets a value from a nested multidimensional array
; Syntax ........: _ArraySet(Byref $aArray, $vValue, $i1[, $i2 = 0[, $i3 = 0[, $i4 = 0[, $i5 = 0[, $i6 = 0[, $i7 = 0[, $i8 = 0[,
;                 $i9 = 0[, $i10 = 0[, $i11 = 0[, $i12 = 0[, $i13 = 0[, $i14 = 0[, $i15 = 0[, $i16 = 0[, $i17 = 0[,
;                 $i18 = 0[, $i19 = 0[, $i20 = 0]]]]]]]]]]]]]]]]]]])
; Parameters ....: $aArray            - [in/out] An array of unknowns.
;                 $vValue             - value to set at specified index.
;                 $i1                 - first array index.
;                 $i2                 - [optional] second array index.
;                 $i3                 - [optional] third array index.
;                 $i4                 - [optional] fourth array index.
;                 $i5                 - [optional] fifth array index.
;                 $i6                 - [optional] sixth array index.
;                 $i7                 - [optional] seventh array index.
;                 $i8                 - [optional] eighth array index.
;                 $i9                 - [optional] ninth array index.
;                 $i10               - [optional] 10th array index.
;                 $i11               - [optional] 11th array index.
;                 $i12               - [optional] 12th array index.
;                 $i13               - [optional] 13th array index.
;                 $i14               - [optional] 14th array index.
;                 $i15               - [optional] 15th array index.
;                 $i16               - [optional] 16th array index.
;                 $i17               - [optional] 17th array index.
;                 $i18               - [optional] 18th array index.
;                 $i19               - [optional] 19th array index.
;                 $i20               - [optional] 20th array index.
; Return values .: Success: True
;                 Error: False, Sets @error to:
;                 |1 - Trying to acces non-array as array
;                 |2 - Not enough dimensions for the last accessed array
;                 |3 - Index out of bounds for a dimension
;                 |all: - @extended contains the dimension in error (according to parameter list)
; Author ........: ProgAndy
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _ArraySet(ByRef $aArray, Const $vValue, $i1, $i2=0, $i3=0, $i4=0, $i5=0, $i6=0, $i7=0, $i8=0, $i9=0, $i10=0, $i11=0, $i12=0, $i13=0, $i14=0, $i15=0, $i16=0, $i17=0, $i18=0, $i19=0, $i20=0)
    ; ProgAndy
    Local Const $NULL = False

    If Not IsArray($aArray) Then Return SetError(1, 1, $NULL)

    Local $iDims = UBound($aArray, 0)

    If @NumParams-2 < $iDims Then Return SetError(2, @NumParams-1, $NULL)

    Local $sAccess = "$aArray"

    For $i = 1 To $iDims
        Local $iIndex = Int(Eval("i" & $i))
        If $iIndex >= UBound($aArray, $i) Then Return SetError(3, $i, $NULL)
        $sAccess &= '[' & $iIndex & ']'
    Next

    If @NumParams-2 > $iDims Then
        $sAccess &= ", $vValue"
        For $i = $iDims+1 To @NumParams-2
            $sAccess &= ", $i" & $i
        Next
        Local $fSuccess = Execute("_ArraySet(" & $sAccess & ")")
        If @error Then SetError(@error, @extended+$iDims)
        Return $fSuccess
    EndIf

    Switch $iDims
        Case 1
            $aArray[$i1] = $vValue
        Case 2
            $aArray[$i1][$i2] = $vValue
        Case 3
            $aArray[$i1][$i2][$i3] = $vValue
        Case 4
            $aArray[$i1][$i2][$i3][$i4] = $vValue
        Case 5
            $aArray[$i1][$i2][$i3][$i4][$i5] = $vValue
        Case 6
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6] = $vValue
        Case 7
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7] = $vValue
        Case 8
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8] = $vValue
        Case 9
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9] = $vValue
        Case 10
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10] = $vValue
        Case 11
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11] = $vValue
        Case 12
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12] = $vValue
        Case 13
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13] = $vValue
        Case 14
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14] = $vValue
        Case 15
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15] = $vValue
        Case 16
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15][$i16] = $vValue
        Case 17
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15][$i16][$i17] = $vValue
        Case 18
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15][$i16][$i17][$i18] = $vValue
        Case 19
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15][$i16][$i17][$i18][$i19] = $vValue
        Case 20
            $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15][$i16][$i17][$i18][$i19][$i20] = $vValue
	EndSwitch

    Return True
EndFunc

ReturnToContents

_ArrayLength

Author: guinness








Global $aArray[2][50]
ConsoleWrite(_ArrayLength($aArray, 2) & @CRLF) ;= > 10 - Total items
ConsoleWrite(_ArrayLength($aArray, 1) & @CRLF) ;= > 5 - Columns
ConsoleWrite(_ArrayLength($aArray, 0) & @CRLF) ;= > 2 - Rows

ConsoleWrite(@CRLF)

Global $aArray[2]
ConsoleWrite(_ArrayLength($aArray, 2) & @CRLF) ;= > 2 - Total items
ConsoleWrite(_ArrayLength($aArray, 1) & @CRLF) ;= > 1 - Columns
ConsoleWrite(_ArrayLength($aArray, 0) & @CRLF) ;= > 2 - Rows

Func _ArrayLength($aArray, $iType = 1)
    Local $iDim = UBound($aArray, 0)

    If $iDim < 0 Or $iDim > 2 Then ; If not a 1D or 2D Array, then return -1 and set @error to non-zero.
        Return SetError(1, 0, -1)
    EndIf

    Switch $iType
        Case 2
            If $iDim = 2 Then
                Return UBound($aArray, 2) * UBound($aArray, 1)
            Else
                Return UBound($aArray, 1)
            EndIf

        Case 1
            If $iDim = 2 Then
                Return UBound($aArray, 2)
            Else
                Return 1
            EndIf

        Case Else
            Return UBound($aArray, 1)
    EndSwitch
EndFunc   ;==>_ArrayLength

ReturnToContents

_ArraySortNum

Author: SmOke_N








; ArraySortNum(ByRef $nArray, $Ascending = 0, $Start = 1)
; Sorts arrays based on TRUE Numerical Order, including Decimals

#include <Array.au3>

; Example sort Array created with StringSplit.
Global $avArray = StringSplit("6,8,10,4,2,13,12,129,106.1,106.4", ",")

_ArraySortNum($avArray, 1)
_ArrayDisplay($avArray, "Sorted Desc starting at 1")

Func _ArraySortNum(ByRef $nArray, $Ascending = 0, $Start = 1)
	For $i = $Start To UBound($nArray) - 2
		Local $SE = $i

		If $Ascending = 0 Then
			For $x = $i To UBound($nArray) - 1
				If Number($nArray[$SE]) < Number($nArray[$x]) Then $SE = $x
			Next
		Else
			For $x = $i To UBound($nArray) - 1
				If Number($nArray[$SE]) > Number($nArray[$x]) Then $SE = $x
			Next
		EndIf

		Local $HLD = $nArray[$i]

		$nArray[$i] = $nArray[$SE]

		$nArray[$SE] = $HLD
	Next
EndFunc   ;==>_ArraySortNum

ReturnToContents

_AssocArray

Author: MilesAhead








; use Scripting.Dictionary object for simple associative arrays
; with string keys. Key comparisons are case insensitive.

Global $myArray
$myArray = _AssocArray()
If @error Then
    MsgBox(0x1010,"_AssocArray() Error", "Error Creating Associative Array!")
    Exit
EndIf

$myArray("AntiqueWhite") = 0xFAEBD7
$myArray("Black") = 0x000000
$myArray("Blue") = 0x0000FF
$myArray("Brown") = 0xA52A2A
$myArray("CadetBlue") = 0x5F9EA0
$myArray("Chocolate") = 0xD2691E
$myArray("Coral") = 0xFF7F50

MsgBox(0x1040,"","Hex for Chocolate Color is: 0x" & Hex($myArray("Chocolate"),6))
_AssocArrayDestroy($myArray)

Func _AssocArray()
    Local $aArray = ObjCreate("Scripting.Dictionary")

    If @error Then
        Return SetError(1, 0, 0)
    EndIf

    $aArray.CompareMode = 1

    Return $aArray
EndFunc   ;==>_AssocArray

Func _AssocArrayDestroy(ByRef $aArray)
    If Not IsObj($aArray) Then
        Return False
    EndIf
    $aArray.RemoveAll()
    $aArray = 0
    Return True
EndFunc   ;==>_AssocArrayDestroy

ReturnToContents

_FuncListToArray

Author: GEOSoft








$aFlist = _FuncListToArray(@ScriptFullPath)
If NOT @Error Then
   For $i = 0 To Ubound($aFlist) -1
      MsgBox(0, "TEST", $aFlist[$i], 2)
   Next
EndIf

Func _FuncListToArray($sStr)
   If FileExists($sStr) Then $sStr = FileRead($sStr)
   Local $sRegEx = "(?i)(?m:^|\n)\s*Func\s+(\w+)\s*\("
   $aRegEx = StringRegExp($sStr, $sRegEx, 3)
   If IsArray($aRegEx) Then Return $aRegEx
   Return SetError(1)
EndFunc

ReturnToContents

Identify Duplicate Values In Arrays

Author: GaryFrost








; Identify Duplicate Values In Arrays
#include <Array.au3>

Global $a1[3] = [1, 2, 3], $a2[5] = [5, 6, 7, 8, 9], $a3[2] = [3, 5]
Global $a_a[4] = [3, $a1, $a2, $a3]
MsgBox(0, "Dupes?", _SearchForDupes($a_a))

Func _SearchForDupes($a_arrays, $i_ReturnType = 0)
	Local $Dupes[1] = [0]

	If $a_arrays[0] < 2 Then Return ''

	For $i = 1 To $a_a[0] - 1
		For $j = $i + 1 To $a_a[0]
			_FindDupe($a_a[$i], $a_a[$j], $Dupes)
		Next
	Next

	If $Dupes[0] = 0 Then Return ''

	_ArraySort($Dupes)

	If Not $i_ReturnType Then
		Local $s_return = ''

		For $x = 1 To $Dupes[0]
			$s_return &= $Dupes[$x] & ','
		Next
		Return StringTrimRight($s_return, 1)
	Else
		Return $Dupes
	EndIf
EndFunc   ;==>_SearchForDupes

Func _FindDupe(ByRef $a_array01, ByRef $a_array02, ByRef $Dupes)
	Local $found = False

	For $i = 0 To UBound($a_array01) - 1
		For $j = 0 To UBound($a_array02) - 1
			If $a_array01[$i] = $a_array02[$j] Then
				$found = False

				For $x = 1 To $Dupes[0]
					If $Dupes[$x] = $a_array01[$i] Then
						$found = True
						ExitLoop
					EndIf
				Next

				If Not $found Then
					$Dupes[0] += 1
					ReDim $Dupes[$Dupes[0] + 1]
					$Dupes[$Dupes[0]] = $a_array01[$i]
				EndIf
			EndIf
		Next
	Next
EndFunc   ;==>_FindDupe

ReturnToContents

_Is1DArray

Author: guinness








Global $sString = "String"
Global $a1DArray[2] = [1, "Row_1"]
Global $a2DArray[2][2] = [[1],["Row_1: Col_1", "Row_1: Col_2"]]

ConsoleWrite("Is the variable $sString a 1D Array?: " & _Is1DArray($sString) & @CRLF)
ConsoleWrite("Is the variable $a1DArray a 1D Array?: " & _Is1DArray($a1DArray) & @CRLF)
ConsoleWrite("Is the variable $a2DArray a 1D Array?: " & _Is1DArray($a2DArray) & @CRLF)

; Check if a variable is a 1D Array.
Func _Is1DArray(ByRef $aArray)
    Return IsArray($aArray) And (UBound($aArray, 0) = 1)
EndFunc   ;==>_Is1DArray

ReturnToContents

_Is2DArray

Author: guinness







Check if a variable is a 2D Array.


Global $sString = "String"
Global $a1DArray[2] = [1, "Row_1"]
Global $a2DArray[2][2] = [[1],["Row_1: Col_1", "Row_1: Col_2"]]

ConsoleWrite("Is the variable $sString a 1D Array?: " & _Is2DArray($sString) & @CRLF)
ConsoleWrite("Is the variable $a1DArray a 1D Array?: " & _Is2DArray($a1DArray) & @CRLF)
ConsoleWrite("Is the variable $a2DArray a 1D Array?: " & _Is2DArray($a2DArray) & @CRLF)

; Check if a variable is a 2D Array.
Func _Is2DArray(ByRef $aArray)
    Return IsArray($aArray) And (UBound($aArray, 0) = 2)
EndFunc   ;==>_Is2DArray

ReturnToContents

_IsInBounds

Author: guinness








#include <Constants.au3>

Local $aArray[5] = ['Item_1', 'Item_2', 'Item_3', 'Item_4', 'Item_5']

ConsoleWrite(_IsInBounds($aArray, 1) & @CRLF) ; Returns True as the Array has 5 items.
ConsoleWrite(_IsInBounds($aArray, 5) & @CRLF) ; Returns False as the Array has 5 items but starts from the 0th index not 1st.
ConsoleWrite(_IsInBounds($aArray, 0) & @CRLF) ; Returns True.

If _IsInBounds($aArray, 4) Then
	MsgBox($MB_SYSTEMMODAL, '', 'Position 4 contains the value: "' & $aArray[4] & '"')
EndIf

Func _IsInBounds(ByRef Const $aArray, $iIndex)
	Local $iDim = UBound($aArray, 0)
	If $iDim < 0 Or $iDim > 2 Then ; If not a 1D or 2D Array, then return -1 and set @error to non-zero.
		Return SetError(1, 0, False)
	EndIf
	Return $iIndex < UBound($aArray, 1)
EndFunc   ;==>_IsInBounds

ReturnToContents

_MultiFileListToArray

Author: Valuater








; Multiple File List to Array

$Files_List = _MultiFileListToArray(@ScriptDir, "*.txt|*.ini")

; for display only
$GUI = GUICreate(" _MultiFileListToArray - DEMO")
$Edit1 = GUICtrlCreateEdit("", 50, 50, 300, 300)
For $x = 1 To UBound($Files_List) - 1
    GUICtrlSetData(-1, $Files_List[$x] & @CRLF, 1)
Next
GUISetState()

While GUIGetMsg() <> -3
WEnd
; end display only

Func _MultiFileListToArray($sPath, $sFilter = "*", $iFlag = 0)
    Local $hSearch, $sFile, $asFileList[1], $sCount
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If (StringInStr($sFilter, "\")) Or (StringInStr($sFilter, "/")) Or (StringInStr($sFilter, ":")) Or (StringInStr($sFilter, ">")) Or (StringInStr($sFilter, "<")) Or (StringStripWS($sFilter, 8) = "") Then Return SetError(2, 2, "")
    $sFilter = (StringSplit($sFilter, "|"))
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
    For $sCount = 1 To $sFilter[0]
        $hSearch = FileFindFirstFile($sPath & "\" & $sFilter[$sCount])
        If $hSearch = -1 Then
            If $sCount = $sFilter[0] Then Return SetError(4, 4, $asFileList)
            ContinueLoop
        EndIf
        While 1
            $sFile = FileFindNextFile($hSearch)
            If @error Then
                SetError(0)
                ExitLoop
            EndIf
            If $iFlag = 1 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then ContinueLoop
            If $iFlag = 2 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop
            ReDim $asFileList[UBound($asFileList) + 1]
            $asFileList[0] = $asFileList[0] + 1
            $asFileList[UBound($asFileList) - 1] = $sFile
        WEnd
        FileClose($hSearch)
    Next
    Return $asFileList
EndFunc   ;==>_MultiFileListToArray

ReturnToContents

Return Min or Max Number From One or Two Arrays

Author: GaryFrost








#include <Array.au3>

Func _MinMaxa($a_nums01, $MaxFlag = 0, $a_nums02 = 0)
   If Not IsArray($a_nums01) Then
      SetError(1)
      Return (0)
   EndIf

   If @NumParams = 3 Then
      If Not IsArray($a_nums02) Then
         SetError(3)
         Return (0)
      EndIf
   EndIf

   Local $idx

   For $idx = 0 To UBound($a_nums01) - 1
      If StringIsFloat($a_nums01[$idx]) Or StringIsInt($a_nums01[$idx]) Then
         $a_nums01[$idx] = Number($a_nums01[$idx])
      Else
         SetError(2)
         Return (0)
      EndIf
   Next

   _ArraySort($a_nums01, $MaxFlag)

   If @NumParams = 3 Then
      For $idx = 0 To UBound($a_nums02) - 1
         If StringIsFloat($a_nums02[$idx]) Or StringIsInt($a_nums02[$idx]) Then
            $a_nums02[$idx] = Number($a_nums02[$idx])
         Else
            SetError(4)
            Return (0)
         EndIf
	  Next

      _ArraySort($a_nums02, $MaxFlag)

	  If $MaxFlag Then
         If Number($a_nums01[0]) > Number($a_nums02[0]) Then
            Return $a_nums01[0]
         Else
            Return $a_nums02[0]
         EndIf
      Else
         If Number($a_nums01[0]) < Number($a_nums02[0]) Then
            Return $a_nums01[0]
         Else
            Return $a_nums02[0]
         EndIf
      EndIf
   EndIf

   Return $a_nums01[0]
EndFunc ;==>_MinMaxa

ReturnToContents