I was reading the official AutoIt Array Parameters, and from what I can tell you have to tell AutoIt how many elements your array has before you can even create it. Since my array will be dynamic according to what the user selects in my interface then I am in need of something like this.
From their page:
But say you don't know the size of the array upfront, because it may come in a variable size when created dynamically.
Local $iMax
Local $data="Element 1|Element 2|Element 3"
; The string in data will be split into an array everywhere | is encountered
Local $arr = StringSplit($data, "|")
If IsArray($arr) Then
$iMax = UBound($arr); get array size
ConsoleWrite("Items in the array: " & $iMax & @LF)
For $i = 0 to $iMax - 1; subtract 1 from size to prevent an out of bounds error
ConsoleWrite($arr[$i] & @LF)
Next
EndIf
I have set up an if
statement to go through the users selections and build the array first:
If GUICtrlRead($Box1) = $GUI_CHECKED Then
$data = "one|two|three"
EndIf
If GUICtrlRead($Box2) = $GUI_CHECKED Then
$data = "four|five|six"
EndIf
If GUICtrlRead($Box3) = $GUI_CHECKED Then
$data = "seven|eight|nine"
EndIf
If the user selected all three boxes I would need something like:
$data = one|two|three|four|five|six|seven|eight|nine
Then at this point I can pass these elements into the example above to loop through all my elements.
How can I build the array through multiple if
statements and come out with one large array?
$data &= "one|two|three"
will Concatenation assignment and add them together. autoitscript.com/autoit3/docs/intro/lang_operators.htm. Then I just ran a regularFor $i = 0 to $iMax - 1
loop to get the results I needed. – Cesar Bielich May 23 '14 at 1:27