Jump to content
Sign in to follow this  
Malkey

My Array Reference File

Recommended Posts

My Array Reference

I noticed the UBound example for help file did not work. And I keep forgetting which parameter number to use for rows, columns, and dimension.

StringSplit( ) function - A recent post on General Help and Support inspired this one.

Dimensioning arrays - I was having trouble dimensioning a three dimensional array, thinking I was going to use it. I found an example on the AutoIT forums and made other examples to see how it was done. I made several arrays with 3 dimensions, a 4 dimensional array, a two and single dimension for completeness, tidy it all up and posted.

; Array examples 


; == Working UBound example for help file v3.2.11.10 (beta)& v3.2.10.0 ===
; 2 dimension array
Dim $myArray[10][20]   ;element 0,0 to 9,19
$rows = UBound($myArray)  ; Also can use UBound($myArray, 1)
$cols = UBound($myArray, 2)
$dims = UBound($myArray, 0)

$output = "The " & $dims & "-dimensional array has, " & _
        $rows & " rows, " & $cols & " columns" & @CRLF & @CRLF

;Enter Data  and  Display $myArray's contents
For $rows = 0 To UBound($myArray, 1) - 1
    For $cols = 0 To UBound($myArray, 2) - 1
        ;Put data into array one at a time @ each pass in the loops
        $myArray[$rows][$cols] = "[" & $rows & "]" & "[" & $cols & "]" 
        
        ; Store contents of array for display in variable "$output"
        $output &= $myArray[$rows][$cols] & "  " 
    Next
    $output &= @CRLF  ; New row
Next
MsgBox(0, "Array Contents, UBound example", $output)
; =========> End of UBound example 



;=== Split string example ============
Local $contents, $arraySp

$string = "a|b|c|d" 
$arraySp = StringSplit($string, "|")

For $count = 0 To $arraySp[0]
    $contents &= "$arraSp[" & $count & "] = " & $arraySp[$count] & @CRLF & @CRLF
Next
MsgBox(0, "Split string example", $contents)
;========> End of Split string example



;====== Fill array examples ==========
; Single dimensional array
Local $array1Dim[4] = [ 0, '[1]', "[" & 2 & "]", '[3]' ]

; 2 dimensional array
Local $array3x4[3][4] = [ [ '[0][0]', '[0][1]', '[0][2]', StringFormat("[%d][%d]", 0, 3) ], _
                          [ '[1][0]', '[1][1]', '[1][2]', '[1][3]' ], _
                          [ '[2][0]', '[2][1]', '[2][2]', '[2][3]' ] ]
                          
; 3 dimensional array
Local $array2x3x4[2][3][4] = [ [ [ '[0][0][0]', '[0][0][1]', '[0][0][2]', '[0][0][3]'  ], _
                                 [ '[0][1][0]', '[0][1][1]', '[0][1][2]', '[0][1][3]'  ], _
                                 [ '[0][2][0]', '[0][2][1]', '[0][2][2]', '[0][2][3]'  ] ], _
                               [ [ '[1][0][0]', '[1][0][1]', '[1][0][2]', '[0][0][3]'  ], _
                                 [ '[1][1][0]', '[1][1][1]', '[1][1][2]', '[0][1][3]'  ], _
                                 [ '[1][2][0]', '[1][2][1]', '[1][2][2]', '[0][2][3]'  ] ] ]

Local $array2x2x2[2][2][2] = [ [ ['[0][0][0]', '[0][0][1]' ], [ '[0][1][0]', '[0][1][1]'] ], _
                               [ ['[1][0][0]', '[1][0][1]' ], [ '[1][1][0]', '[1][1][1]'  ] ] ]

Local $array3x2x2[3][2][2] = [ [ [ '[0][0][0]', '[0][0][1]'  ], [ '[0][1][0]', '[0][1][1]' ] ], _
                               [ [ '[1][0][0]', '[1][0][1]'  ], [ '[1][1][0]', '[1][1][1]' ] ], _
                               [ [ '[2][0][0]', '[2][0][1]'  ], [ '[2][1][0]', '[2][1][1]' ] ] ]

Local $array2x3x3[2][3][3] = [ [ [ '[0][0][0]', '[0][0][1]', '[0][0][2]'  ], _
                                 [ '[0][1][0]', '[0][1][1]', '[0][1][2]'  ], _
                                 [ '[0][2][0]', '[0][2][1]', '[0][2][2]'  ] ], _
                               [ [ '[1][0][0]', '[1][0][1]', '[1][0][2]'  ], _
                                 [ '[1][1][0]', '[1][1][1]', '[1][1][2]'  ], _
                                 [ '[1][2][0]', '[1][2][1]', '[1][2][2]'  ] ] ]

Local $array2x4x4[2][4][4] = [ [ [ '[0][0][0]', '[0][0][1]', '[0][0][2]', '[0][0][3]' ], _
                                 [ '[0][1][0]', '[0][1][1]', '[0][1][2]', '[0][1][3]' ], _
                                 [ '[0][2][0]', '[0][2][1]', '[0][2][2]', '[0][2][3]' ], _
                                 [ '[0][3][0]', '[0][3][1]', '[0][3][2]', '[0][3][3]' ] ], _
                               [ [ '[1][0][0]', '[1][0][1]', '[1][0][2]', '[1][0][3]' ], _
                                 [ '[1][1][0]', '[1][1][1]', '[1][1][2]', '[1][1][3]' ], _
                                 [ '[1][2][0]', '[1][2][1]', '[1][2][2]', '[1][2][3]' ], _
                                 [ '[1][3][0]', '[1][3][1]', '[1][3][2]', '[1][3][3]' ] ] ]

; 4 dimensional array
Local $array2x2x2x2[2][2][2][2] = [[[['[0][0][0][0]','[0][0][0][1]'],['[0][0][1][0]','[0][0][1][1]']], _
                                    [['[0][1][0][0]','[0][1][0][1]'],['[0][1][1][0]','[0][1][1][1]']]], _
                                   [[['[1][0][0][0]','[1][0][0][1]'],['[1][0][1][0]','[1][0][1][1]']], _
                                    [['[1][1][0][0]','[1][1][0][1]'],['[1][1][1][0]','[1][1][1][1]']]]]
$a = 0x0f456789  ;  345   ;

;MsgBox(0,"","0x00" & hex($a ,6))

MsgBox(0, "Fill array examples", "$array1Dim  [0]       =  " & $array1Dim [0] & @CRLF & @CRLF & _
                                "$array1Dim  [1]       =  " & $array1Dim [1] & @CRLF & @CRLF & _
                                "$array1Dim  [2]       =  " & $array1Dim [2] & @CRLF & @CRLF & _
                                "$array1Dim  [3]       =  " & $array1Dim [3] & @CRLF & @CRLF & _
                                "$array3x4   [0][3]    =  " & $array3x4 [0][3] & @CRLF & @CRLF & _
                                "$array2x3x4 [1][0][1] =  " & $array2x3x4[1][0][1] & @CRLF & @CRLF & _
                                "$array2x2x2 [1][0][1] =  " & $array2x2x2[1][0][1] & @CRLF & @CRLF & _
                                "$array3x2x2 [1][0][1] =  " & $array3x2x2[1][0][1] & @CRLF & @CRLF & _
                                "$array2x3x3 [1][0][1] =  " & $array2x3x3[1][0][1] & @CRLF & @CRLF & _
                                "$array2x4x4 [1][2][3] =  " & $array2x4x4[1][2][3] & @CRLF & @CRLF & _
                                "$array2x2x2x2 [1][1][0][1] =  " & $array2x2x2x2[1][1][0][1] & @CRLF)
;=======> End of fill array examples

This is suppose to reduce confusion with arrays. So, don't get caught up in the 3 dimensional arrays like I did.

If anyone has other array related examples and willing to share, please do.

Edit: 10/05/08

Sort array - Siao's ArraySort link http://www.autoitscript.com/forum/index.ph...st&p=474072

Edit: 12/05/08

Join arrays

monoceres - http://www.autoitscript.com/forum/index.ph...st&p=520053

Merge arrays weaponx - http://www.autoitscript.com/forum/index.ph...st&p=429815

Edit:14/05/08

Found this handy AutoIt Snippets site about arrays:

http://quadryders.com/phpcc/browse.php?cid=3

Edited by Malkey

Share this post


Link to post
Share on other sites

Algorithm For sorting arrays.

Simple one: Wiki Source

Better ones: More sorting Algorithm

be cool


You can help! Donate to AutoIt! or, visit ClimatePREDICTION.netMy posts:Travian Bot Example (100+ servers) BETAHow to Host you code/app for free! (unlimited team number) (Public or Private)"Sir, we're surrounded!" "Excellent. We can attack in any direction!"

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  

×
×
  • Create New...