adrian1386 Posted January 5, 2006 Share Posted January 5, 2006 I have made some ok scripts with the help of this forum and lately have been seeing a lot of talk about arrays. What are they and how are they useful? Thanks in advance! Link to comment Share on other sites More sharing options...
poisonkiller Posted January 5, 2006 Share Posted January 5, 2006 Well... If you use arrays, you dont have to use many different variables. Example: Dim $array[5];Declares 5 arrays $array[1] = "Hello!" $array[2] = "Goodbye!" $array[3] = "Some more arrays" $array[4] = "Fourth array" For $i = 1 to 4 $result = $array[$i] &@CRLF Next MsgBox(0, "", $result) ;Result will be: ;Hello! ;Goodbye! ;Some more arrays ;Fourth array And of course you can do a lot more things with arrays. Link to comment Share on other sites More sharing options...
nfwu Posted January 5, 2006 Share Posted January 5, 2006 Arrays are a form of data structure.If you need to keep track of a number of items tht are of the same data type, the best solution is to use an array. For example, a bank may want to keep track of the ballances for each of the 12 months, without arrays you could create 12 variables: (inefficent)$Jan_balance $Feb_balance $Mar_balance $Apr_balance $May_balance $Jun_balance $Jul_balance $Aug_balance $Sep_balance $Oct_balance $Nov_balance $Dec_balanceTo use these variables, you must determine which month it is an then switch/ifelse among the correct variables.If $month == 0 Then $jan_ballance += $amount_to_add Elseif $month == 1 Then $feb_ballance += $amount_to_add ;... code cut ... ElseIf $month == 11 Then $dec_ballance += $amount_to_add EndifGet the idea, but with arrays:Dim $balance[12] ;; $balance[0] is january, $balance[11] is december $balance[$month] += $amount_to_addRECAP:Declaration:Dim $array_name[<number_of_elements>]Access:$array_name[<element_number>]Remember that for Dim $array_name[12] makes a twelve element array, element numbers ranging from 0 to 11. (always start with 0!!!) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 11, 2006 Moderators Share Posted January 11, 2006 (edited) Well... If you use arrays, you dont have to use many different variables. Example: Dim $array[5];Declares 5 arrays $array[1] = "Hello!" $array[2] = "Goodbye!" $array[3] = "Some more arrays" $array[4] = "Fourth array" For $i = 1 to 4 $result = $array[$i] &@CRLF Next MsgBox(0, "", $result) ;Result will be: ;Hello! ;Goodbye! ;Some more arrays ;Fourth array And of course you can do a lot more things with arrays. Result this way will be: Fourth array You need to have the $result in with the adding and Dim/Local the variable $result: Dim $array[5];Declares 5 arrays $array[1] = "Hello!" $array[2] = "Goodbye!" $array[3] = "Some more arrays" $array[4] = "Fourth array" Dim $result For $i = 1 to 4 $result = $result & $array[$i] &@CRLF Next MsgBox(0, "", $result) ;Result will be: ;Hello! ;Goodbye! ;Some more arrays ;Fourth array Edit or with Beta: $result &= $array[$i] & @CRLF Edited January 11, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now