Understanding Arrays
#1
Posted 10 August 2012 - 04:35 PM
I'm having a hard time wrapping my brain around Arrays. Specifically, multi-dimensional, as well as dimension and entry limits.'
I already read the AutoIt docs page a couple of times.
Anyone have a better explanation and/or links?
Thanks!
#2
Posted 10 August 2012 - 04:47 PM
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#3
Posted 10 August 2012 - 04:47 PM
I recommend the Arrays tutorial in the Wiki. Please post again if you still have questions.
M23
Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display
RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items
#5
Posted 10 August 2012 - 07:10 PM
Remember in geometry when you had to calculate distances in a 3 dimensional object? you had your x,y, and z axis. Same idea.
x = rows
y = columns
z = depth
Local $array[1] ; single dimension array with 1 element Local $2D[1][2] ; two dimensional array with 2 indexes and 1 element in each index. ; i.e. $2D[0][0], $2D[0][1] Local $3D[1][2][2] ; three dimensional array with 2 planes, 2 indexes on each plane, and 1 elements in each index ; i.e. $3D[0][0][0], $3D[0][1][0], $3D[0][0][1], $3D[0][1][1]
#6
Posted 10 August 2012 - 08:39 PM
It's just another way of labelling the same variables or "mailboxes" that you're creating.
$aArray[24] is the same thing as $aArray[3][8] (3 x 8 = 24) which is the same thing as $aArray[3][2][4] (3 x 2 x 4 = 24).
They are all just a table of 24 variables.
If your 3-story apartment building has 24 units and you just want to store all the apartment numbers then use $aArray[24] (apt#).
If you want to organize them by floor you could create the same 24 boxes but reference them as $aArray[3][8] (floor/apt#)
If you had a reason to keep the apartments on the north side of the building separate from those on the south side, then you could setup your 24 mailboxes as $aArray[3][2][4] (floor/north-south/apt#)
When you reference the 17th element of the 1-dimension array; $aArray[17], it is the same thing internally as referencing element $aArray[2][0][1] of the 3-dimension array (2 x 8 + 0 x 4 + 1 x 1 = 17)
Hope I haven't made things worse
Edit: You could simulate any number of dimensions using a 1-dimension array and a few lines of code. This is, at least conceptually, the same thing that goes on internally when you decide to split your array into different dimensions:
Global $aApartments[24] = ["1A","1B","1C","1D","1E","1F","1G","1H","2A","2B","2C","2D","2E","2F","2G","2H","3A","3B","3C","3D","3E","3F","3G","3H"] MsgBox(0, "1-Dimension", Dimension_Simulator("24", "17")) ; get element [17] of $aArray[24] MsgBox(0, "2-Dimension", Dimension_Simulator("3*8", "2|1")) ; get element [2][1] of $aArray[3][8] MsgBox(0, "3-Dimension", Dimension_Simulator("3*2*4", "2|0|1")) ; get element [2][0][1] of $aArray[3][2][4] Func Dimension_Simulator($structure, $element) Local $aStructure = StringSplit($structure, "*") Local $iSize = Execute($structure) ; total elements Local $aElement = StringSplit($element, "|") Local $iTarget For $x = 1 to $aElement[0] ; calculate element offset $iTarget += $aElement[$x] * ($iSize / $aStructure[$x]) $iSize /= $aStructure[$x] Next Return $aApartments[$iTarget] EndFunc
Edited by Spiff59, 11 August 2012 - 06:20 AM.
- tes5884 likes this
#7
Posted 13 August 2012 - 02:08 PM
#8
Posted 13 August 2012 - 02:59 PM
toast = $var[2][2]
Does that mean I can have values like the following;
$var[0][0]
$var[0][1]
$var[0][2]
$var[1][0]
$var[1][1]
$var[1][2]
$var[2][0]
$var[2][1]
$var[2][2]
or am I missing something?
Thanks!!!
Edited by tes5884, 13 August 2012 - 03:00 PM.
#9
Posted 13 August 2012 - 03:04 PM
Array elements always start with an index of 0. If you have an $array[7] the index goes from 0 to 6 (or "UBound($array, 1) - 1)".
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#10
Posted 13 August 2012 - 03:06 PM
Does index 0 hold a comparable value to any other number?Your list of array elements is correct.
Array elements always start with an index of 0. If you have an $array[7] the index goes from 0 to 6 (or "UBound($array, 1) - 1)".
In other words, does the first index (0), point to an element just like any other index ? or is it any different.
#11
Posted 13 August 2012 - 03:11 PM
If it is a two dimensional array then $array[0][0] contains the number of rows and $array[0][1] contains the number of columns.
Check function StringSplit as an example. You can decide if the function returns a zero- or one-based array.
- tes5884 likes this
UDFs:
Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts
WordEX (2012-12-29 - Version 1.3 released) - Download
ExcelEX (2013-05-11 - Alpha 4 released) - Download
#12
Posted 13 August 2012 - 03:16 PM
Many functions that return an array (_FileListToArray()) use the 0 index to hold specific information. In the case of _FileListToArray(), the 0 index holds the total file/folder count. For these functions you can iterate over them as follows:
For 0-based arrays, you can iterate over them as:
#13
Posted 13 August 2012 - 03:17 PM
Edited by tes5884, 13 August 2012 - 03:17 PM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users




