E1M1 Posted June 8, 2010 Share Posted June 8, 2010 (edited) I can't use variables with array. Here's list of codes and results Edit:Problem 1 was because of my math, but still can't find find fix for 2nd problem Any ideas? 1) $a = 10 Dim $color[$a] No error $colorx = 73 $starty = 510 $endy = 585 $a = $starty - $endy Dim $color[$a] C:\Users\rain\Desktop\test.au3 (5) : ==> Array variable subscript badly formatted.: Dim $color[$a] Dim $color[^ ERROR 2) $color[10] &= hex(PixelGetColor($colorx,$i))&')' & @CRLF No errors $color[$i-($starty+1)] &= hex(PixelGetColor($colorx,$i))&')' & @CRLF C:\Users\rain\Desktop\test.au3 (13) : ==> Array variable subscript badly formatted.: $color[$i-($starty+1)] &= hex(PixelGetColor($colorx,$i))&')' & @CRLF $color[^ ERROR Here's full code $colorx = 73 $starty = 510 $endy = 585 ;~ $a = $starty - $endy Dim $color[100] WinActivate("untitled") WinWaitActive("untitled") Opt("PixelCoordMode", 2) ;Get Normal color $color = "" for $i = $starty to $endy $color[$i-($starty+1)] &= hex(PixelGetColor($colorx,$i))&')' & @CRLF ;~ $color &= 'GUICtrlCreateLabel("",0,'&($i*5)-2550&',5,5)' & @CRLF &'GUICtrlSetBkColor(-1, 0x'&hex(PixelGetColor($colorx,$i))&')' & @CRLF Next Edited June 8, 2010 by E1M1 edited Link to comment Share on other sites More sharing options...
Spiff59 Posted June 8, 2010 Share Posted June 8, 2010 Without looking at the full code, the first error results form trying to declare an array with a negative number of elements. Using something like "Dim $color[Abs($start - $end) + 1]" would get you the right number of array elements. You'd still need to store a variable indicating the offset between the lowest array element (0) and your $start variable. Then you'd need to adjust by that value anytime you referenced the array. Link to comment Share on other sites More sharing options...
GEOSoft Posted June 8, 2010 Share Posted June 8, 2010 (edited) Not an AutoIt bug. It's a keyboard operator bug. 510 - 585 ends up in a negative number and you can't dimension an array on the negative side. I think you wanted $colorx = 73 $starty = 510 $endy = 585 $a = $endy - $starty Dim $color[$a] Edited June 8, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
E1M1 Posted June 8, 2010 Author Share Posted June 8, 2010 yeah i found that both are caused by my stupidy in math.... edited Link to comment Share on other sites More sharing options...
Spiff59 Posted June 8, 2010 Share Posted June 8, 2010 (edited) The $color = "" statement in there also trashes $color as being defined as an array and converts it to a simple (empty) variable. The &= operator isn't necessary either as it appends to existing data, yet the elements all start as empty and are only referenced once. I learn best by "doing", maybe you do to, try playing with this... #include <array.au3> Global $colorx = 73, $starty = 510, $endy = 585, $len = $endy - $starty + 1 Global $color[$len + 1] $color[0] = $len ;WinActivate("untitled") ;WinWaitActive("untitled") Opt("PixelCoordMode", 2) ;Get Normal color for $i = $starty to $endy MouseMove($colorx, $i, 0) sleep(10) $color[$i - $starty + 1] = hex(PixelGetColor($colorx,$i)) & ')' & @CRLF ;~ $color &= 'GUICtrlCreateLabel("",0,'&($i*5)-2550&',5,5)' & @CRLF &'GUICtrlSetBkColor(-1, 0x'&hex(PixelGetColor($colorx,$i))&')' & @CRLF Next _ArrayDisplay($color) Edit: I just stuck the Mousemove(), Sleep() and _ArrayDisplay() in there as eye-candy for testing. Edited June 8, 2010 by Spiff59 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