Snippets ( AutoIt Array ): Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
m (grrr)
(Converted snippets to Template:Snippet Header)
Line 1: Line 1:
__TOC__
__TOC__
[[category:Snippets]]
[[category:Snippets]]


{{Snippet Credit Header}}
{{Snippet Credit Header}}


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _1Dto2DArray() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header
 
|UDFName=_1Dto2DArray
<syntaxhighlight lang="autoit">
|AuthorURL=35302-guinness
|AuthorName=guinness
|ReturnToTop=1
|AutoItCode=
#include <Array.au3>
#include <Array.au3>


Line 29: Line 33:
     Return $aReturn
     Return $aReturn
EndFunc  ;==>_1Dto2DArray
EndFunc  ;==>_1Dto2DArray
</syntaxhighlight>
}}


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _ArrayAddEx() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header
<syntaxhighlight lang="autoit">
|UDFName=_ArrayAddEx
|AuthorURL=35302-guinness
|AuthorName=guinness
|ReturnToTop=1
|AutoItCode=
#include <Array.au3>
#include <Array.au3>


Line 84: Line 92:
     Return $iCount - 1
     Return $iCount - 1
EndFunc  ;==>_ArrayAddEx
EndFunc  ;==>_ArrayAddEx
</syntaxhighlight>
}}
[[#top|Return To Contents]]
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _ArrayEmpty() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
 
<syntaxhighlight lang="autoit">
; Creates Empty 1D & 2D Array's


{{Snippet Header
|UDFName=_ArrayEmpty
|AuthorURL=35302-guinness
|AuthorName=guinness
|ReturnToTop=1
|Desc=Creates Empty 1D & 2D Array's
|AutoItCode=
#include <Array.au3>
#include <Array.au3>


Line 113: Line 122:
     EndSwitch
     EndSwitch
EndFunc  ;==>_ArrayEmpty
EndFunc  ;==>_ArrayEmpty
</syntaxhighlight>
}}
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _ArrayGet() & _ArraySet() ~ Author - [http://www.autoitscript.com/forum/user/31965-progandy/ ProgAndy] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header
; Easy access for nested arrays up to 20 nested dimensions (including multidimensional arrays)
|UDFName=_ArrayGet
|AuthorURL=31965-progandy
|AuthorName=ProgAndy
|ReturnToTop=1
|Desc=Easy access for nested arrays up to 20 nested dimensions (including multidimensional arrays)
|AutoItCode=
Local $b[2] = ["a", "b"]
Local $b[2] = ["a", "b"]
Local $a[3][2] = [[0, -1], [$b, "x"], [1, -2]]
Local $a[3][2] = [[0, -1], [$b, "x"], [1, -2]]
Line 125: Line 137:


MsgBox(0, "", _ArrayGet($a, 1, 0, 1) & " # " & @error)
MsgBox(0, "", _ArrayGet($a, 1, 0, 1) & " # " & @error)
_ArraySet($a, $c, 1, 0, 0)
MsgBox(0, @error, @extended)
MsgBox(0, "", _ArrayGet($a, 1, 0, 0, 3))


; #FUNCTION# ====================================================================================================================
; #FUNCTION# ====================================================================================================================
Line 193: Line 202:
     EndIf
     EndIf
EndFunc
EndFunc
}}


{{Snippet Header
|UDFName=_ArraySet
|AuthorURL=31965-progandy
|AuthorName=ProgAndy
|ReturnToTop=1
|Desc=Easy access for nested arrays up to 20 nested dimensions (including multidimensional arrays)
|AutoItCode=
Local $b[2] = ["a", "b"]
Local $a[3][2] = [[0, -1], [$b, "x"], [1, -2]]


Local $c[5] = [11, 22, 33, 44, 55]
_ArraySet($a, $c, 1, 0, 0)


; #FUNCTION# ====================================================================================================================
; #FUNCTION# ====================================================================================================================
Line 299: Line 321:
         Case 20
         Case 20
             $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15][$i16][$i17][$i18][$i19][$i20] = $vValue
             $aArray[$i1][$i2][$i3][$i4][$i5][$i6][$i7][$i8][$i9][$i10][$i11][$i12][$i13][$i14][$i15][$i16][$i17][$i18][$i19][$i20] = $vValue
    EndSwitch
EndSwitch
 
     Return True
     Return True
EndFunc
EndFunc
</syntaxhighlight>
}}


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _ArrayLength() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header
 
|UDFName=_ArrayLength
<syntaxhighlight lang="autoit">
|AuthorURL=35302-guinness
|AuthorName=guinness
|ReturnToTop=1
|AutoItCode=
Local $aArray[2][50]
Local $aArray[2][50]
ConsoleWrite(_ArrayLength($aArray, 2) & @CRLF) ;= > 10 - Total items
ConsoleWrite(_ArrayLength($aArray, 2) & @CRLF) ;= > 10 - Total items
Line 344: Line 370:
     EndSwitch
     EndSwitch
EndFunc  ;==>_ArrayLength
EndFunc  ;==>_ArrayLength
</syntaxhighlight>
}}


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _ArraySortNum() ~ Author - [http://www.autoitscript.com/forum/user/4813-smoke-n/ SmOke_N] '''</blockquote> =====
{{Snippet Header
 
|UDFName=_ArraySortNum
<syntaxhighlight lang="autoit">
|AuthorURL=4813-smoke-n
|AuthorName=SmOke_N
|ReturnToTop=1
|AutoItCode=
; ArraySortNum(ByRef $nArray, $Ascending = 0, $Start = 1)
; ArraySortNum(ByRef $nArray, $Ascending = 0, $Start = 1)
; Sorts arrays based on TRUE Numerical Order, including Decimals
; Sorts arrays based on TRUE Numerical Order, including Decimals
Line 377: Line 406:
Next
Next
EndFunc  ;==>_ArraySortNum
EndFunc  ;==>_ArraySortNum
</syntaxhighlight>
}}


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _AssocArray() ~ Author - [http://www.autoitscript.com/forum/user/31149-milesahead/ MilesAhead] '''</blockquote> =====
{{Snippet Header
 
|UDFName=_AssocArray
<syntaxhighlight lang="autoit">
|AuthorURL=31149-milesahead
|AuthorName=MilesAhead
|ReturnToTop=1
|AutoItCode=
; use Scripting.Dictionary object for simple associative arrays
; use Scripting.Dictionary object for simple associative arrays
; with string keys. Key comparisons are case insensitive.
; with string keys. Key comparisons are case insensitive.
Line 420: Line 452:
     Return True
     Return True
EndFunc  ;==>_AssocArrayDestroy
EndFunc  ;==>_AssocArrayDestroy
</syntaxhighlight>
}}
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _FuncListToArray() ~ Author - [http://www.autoitscript.com/forum/user/52-geosoft/ GEOSoft] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header
|UDFName=_FuncListToArray
|AuthorURL=52-geosoft
|AuthorName=GEOSoft
|ReturnToTop=1
|AutoItCode=
$aFlist = _FuncListToArray(@ScriptFullPath)
$aFlist = _FuncListToArray(@ScriptFullPath)
If NOT @Error Then
If NOT @Error Then
Line 439: Line 474:
   Return SetError(1)
   Return SetError(1)
EndFunc
EndFunc
</syntaxhighlight>
}}
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Identify Duplicate Values In Arrays ~ Author - [http://www.autoitscript.com/forum/user/1967-garyfrost/ GaryFrost] '''</blockquote> =====


<syntaxhighlight lang="autoit">
{{Snippet Header
|UDFName=Identify Duplicate Values In Arrays
|AuthorURL=1967-garyfrost
|AuthorName=GaryFrost
|ReturnToTop=1
|AutoItCode=
; Identify Duplicate Values In Arrays
; Identify Duplicate Values In Arrays
#include <Array.au3>
#include <Array.au3>
Line 494: Line 532:
Next
Next
EndFunc  ;==>_FindDupe
EndFunc  ;==>_FindDupe
</syntaxhighlight>
}}


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _Is1DArray() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header
<syntaxhighlight lang="autoit">
|UDFName=_Is1DArray
|AuthorURL=35302-guinness
|AuthorName=guinness
|ReturnToTop=1
|AutoItCode=
Local $sString = 'String'
Local $sString = 'String'
Local $a1DArray[2] = [1, 'Row_1']
Local $a1DArray[2] = [1, 'Row_1']
Line 510: Line 552:
     Return IsArray($aArray) And (UBound($aArray, 0) = 1)
     Return IsArray($aArray) And (UBound($aArray, 0) = 1)
EndFunc  ;==>_Is1DArray
EndFunc  ;==>_Is1DArray
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _Is2DArray() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header
<syntaxhighlight lang="autoit">
|UDFName=_Is2DArray
|AuthorURL=35302-guinness
|AuthorName=guinness
|ReturnToTop=1
|Desc=Check if a variable is a 2D Array.
|AutoItCode=
Local $sString = 'String'
Local $sString = 'String'
Local $a1DArray[2] = [1, 'Row_1']
Local $a1DArray[2] = [1, 'Row_1']
Line 527: Line 573:
     Return IsArray($aArray) And (UBound($aArray, 0) = 2)
     Return IsArray($aArray) And (UBound($aArray, 0) = 2)
EndFunc  ;==>_Is2DArray
EndFunc  ;==>_Is2DArray
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsInBounds() ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header
<syntaxhighlight lang="autoit">
|UDFName=_IsInBounds
|AuthorURL=35302-guinness
|AuthorName=guinness
|ReturnToTop=1
|AutoItCode=
Local $aArray[5] = ['Item_1', 'Item_2', 'Item_3', 'Item_4', 'Item_5']
Local $aArray[5] = ['Item_1', 'Item_2', 'Item_3', 'Item_4', 'Item_5']


Line 549: Line 598:
     Return $iIndex < UBound($aArray, 1)
     Return $iIndex < UBound($aArray, 1)
EndFunc  ;==>_IsInBounds
EndFunc  ;==>_IsInBounds
</syntaxhighlight>
}}
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _MultiFileListToArray() ~ Author - [http://www.autoitscript.com/forum/user/4920-valuater/ Valuater] '''</blockquote> =====
{{Snippet Header
 
|UDFName=_MultiFileListToArray
<syntaxhighlight lang="autoit">
|AuthorURL=4920-valuater
|AuthorName=Valuater
|ReturnToTop=1
|AutoItCode=
; Multiple File List to Array
; Multiple File List to Array


Line 599: Line 650:
     Return $asFileList
     Return $asFileList
EndFunc  ;==>_MultiFileListToArray
EndFunc  ;==>_MultiFileListToArray
</syntaxhighlight>
}}
 
===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Return Min Or Max Number From 1 Or 2 Arrays ~ Author - [http://www.autoitscript.com/forum/user/1967-garyfrost/ GaryFrost] '''</blockquote> =====
 
<syntaxhighlight lang="autoit">
; Return Min Or Max Number From 1 Or 2 Arrays


{{Snippet Header
|UDFName=Return Min or Max Number From One or Two Arrays
|AuthorURL=1967-garyfrost
|AuthorName=GaryFrost
|ReturnToTop=1
|AutoItCode=
#include <Array.au3>
#include <Array.au3>


Line 613: Line 665:
       Return (0)
       Return (0)
   EndIf
   EndIf
   If @NumParams = 3 Then
   If @NumParams = 3 Then
       If Not IsArray($a_nums02) Then
       If Not IsArray($a_nums02) Then
Line 619: Line 672:
       EndIf
       EndIf
   EndIf
   EndIf
;
 
   Local $idx
   Local $idx
;
 
   For $idx = 0 To UBound($a_nums01) - 1
   For $idx = 0 To UBound($a_nums01) - 1
       If StringIsFloat($a_nums01[$idx]) Or StringIsInt($a_nums01[$idx]) Then
       If StringIsFloat($a_nums01[$idx]) Or StringIsInt($a_nums01[$idx]) Then
Line 630: Line 683:
       EndIf
       EndIf
   Next
   Next
   _ArraySort($a_nums01, $MaxFlag)
   _ArraySort($a_nums01, $MaxFlag)
   If @NumParams = 3 Then
   If @NumParams = 3 Then
       For $idx = 0 To UBound($a_nums02) - 1
       For $idx = 0 To UBound($a_nums02) - 1
Line 639: Line 694:
             Return (0)
             Return (0)
         EndIf
         EndIf
      Next
  Next
 
       _ArraySort($a_nums02, $MaxFlag)
       _ArraySort($a_nums02, $MaxFlag)
      If $MaxFlag Then
 
  If $MaxFlag Then
         If Number($a_nums01[0]) > Number($a_nums02[0]) Then
         If Number($a_nums01[0]) > Number($a_nums02[0]) Then
             Return $a_nums01[0]
             Return $a_nums01[0]
Line 655: Line 712:
       EndIf
       EndIf
   EndIf
   EndIf
   Return $a_nums01[0]
   Return $a_nums01[0]
EndFunc ;==>_MinMaxa
EndFunc ;==>_MinMaxa
</syntaxhighlight>
}}

Revision as of 16:49, 12 November 2012


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


Author: guinness








Author: guinness








Author: guinness







Creates Empty 1D & 2D Array's


Author: ProgAndy







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


Author: ProgAndy







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


Author: guinness








Author: SmOke_N








Author: MilesAhead








Author: GEOSoft








Author: GaryFrost








Author: guinness








Author: guinness







Check if a variable is a 2D Array.


Author: guinness








Author: Valuater








Author: GaryFrost