BALA Posted December 11, 2006 Posted December 11, 2006 I've read the manual and have talked to a couple of people, but I still can't figure out how to create and use arrays. Could someone give me a simple breakdown of how to create and use an array. [font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
mikehunt114 Posted December 11, 2006 Posted December 11, 2006 $aArray = _ArrayCreate("11", "Jim", "13f", "animal", "!!") _ArrayDisplay( $aArray, "Array created with _ArrayCreate" ) For $i = 0 to (UBound($aArray) - 1) MsgBox(0, "Value of array element #" & $i, $aArray[$i]) Next IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
BALA Posted December 11, 2006 Author Posted December 11, 2006 (edited) $aArray = _ArrayCreate("11", "Jim", "13f", "animal", "!!") _ArrayDisplay( $aArray, "Array created with _ArrayCreate" ) For $i = 0 to (UBound($aArray) - 1) MsgBox(0, "Value of array element #" & $i, $aArray[$i]) Next So is there a way to have the elements in the array be a variable, since I want to use the array to record the position of my mouse when I click it and I want to use the array to store the position each time I click. (I'm creating a program to record the mouse clicks of a user, as to have the computer do redundant tasks for him, and don't know how many times he will click.) Edited December 11, 2006 by BALA [font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
mikehunt114 Posted December 11, 2006 Posted December 11, 2006 So is there a way to have the elements in the array be a variable, since I want to use the array to record the position of my mouse when I click it and I want to use the array to store the position each time I click. Sure, see where I used $aArray[$i]? You can grab the contents of any element and do what you will with it. If you want to assign a certain element you can do something like: $val = $aArray[1] But arrays are better used in a loop situation, like I showed above. You could always assign an element's value to a variable inside the loop itself too. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
mikehunt114 Posted December 11, 2006 Posted December 11, 2006 This would record the mouse coordinates into an array each time you click the mouse. The x-coordinates would be each even element, and the y-coordinates would be each odd element. #include <Array.au3> #include <Misc.au3> Dim $Position, $i = 0, $Record[1] While 1 If _IsPressed("01") Then $Position = MouseGetPos() $x = $Position[0] $y = $position[1] ReDim $Record[$i + 2] $Record[$i] = $x $Record[$i + 1] = $y $i += 2 _ArrayDisplay($Record, "") EndIf sleep(10) WEnd IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
BALA Posted December 11, 2006 Author Posted December 11, 2006 This would record the mouse coordinates into an array each time you click the mouse. The x-coordinates would be each even element, and the y-coordinates would be each odd element. #include <Array.au3> #include <Misc.au3> Dim $Position, $i = 0, $Record[1] While 1 If _IsPressed("01") Then $Position = MouseGetPos() $x = $Position[0] $y = $position[1] ReDim $Record[$i + 2] $Record[$i] = $x $Record[$i + 1] = $y $i += 2 _ArrayDisplay($Record, "") EndIf sleep(10) WEnd Wow, thanks [font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
mikehunt114 Posted December 11, 2006 Posted December 11, 2006 Wow, thanks Hopefully arrays won't be so ominous for you after you take a look at it. I'm not all that good with arrays. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
The Kandie Man Posted December 11, 2006 Posted December 11, 2006 (edited) Here, i improved mikehunt's code: #include <Misc.au3> Dim $Position, $i = 0, $Record[1][2] While 1 If _IsPressed("01") Then $Position = MouseGetPos() ReDim $Record[$i + 1][2] $Record[$i][0] = $Position[0] $Record[$i][1] = $position[1] consoleWrite($Record[$i][0] & @LF & $Record[$i][ 1] & @LF) Msgbox(0,"Mouse Position","x = "&$Record[$i][0] & @LF & "y = "& $Record[$i][1] & @LF) $i += 1 EndIf sleep(10) WEnd Every $Record[$i][0] value will be the x position while every $Record[$i][1] value will be the y position. Makes it easier to manage since it is a two dimensional array. Edited December 11, 2006 by The Kandie Man "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire
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