marko001 Posted November 8, 2010 Share Posted November 8, 2010 Hi all, I created a gui with several (dynamic) buttons: Func _create_Input() $Alto = 165 $Sinistra = 176 $delta = 0 $multiplier = 0 local $a, $t For $t = 0 To 24 For $a = 0 To 12 $InputBLD[$t][$a] = GUICtrlCreateButton("", $Sinistra + $delta * $multiplier, $Alto, 50, 21, BitOR($ES_READONLY,$ES_CENTER)) $delta = 55 $multiplier = $multiplier + 1 GUICtrlSetState($InputBLD[$t][$a],$GUI_HIDE) Next $Alto = $Alto + 25 $delta = 0 $multiplier = 0 Next EndFunc Now i Have 13x25 buttons, hidden (for faster loading. Only needed rows will be shown later if needed) Let's say I have only 2 rows: $InputBLD[0][0]....to [12] $InputBLD[1][0]....to [12] for a total of 26 buttons. Is there a way to do actions without declaring before all of them? I mean, i'm looking to do something like: case $InputBLD[$h][$v] do something instead of declaring global $InputBLD[0][0],$InputBLD[0][1],$InputBLD[0][2],...,$InputBLD[24][13] I tried and it didn't work (as expected). Thanks a lot, Marco Link to comment Share on other sites More sharing options...
JohnOne Posted November 8, 2010 Share Posted November 8, 2010 You only need to declare $InputBLD[24][13] (if thats the bounds of your array. A variable must be declared before you can test it, in one fasion or another. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Mat Posted November 8, 2010 Share Posted November 8, 2010 If you are declaring them one after the other (as it looks like you are), then the id's for the controls will be consecutive numbers. We can use this to speciafy a range. For example, if you make a GUI with twelve buttons (and no other controls) starting from an id of 1 (I'm not suire where they start from) then the buttons will be all the id's in the range 1 to 12. For the case this is simple: Case $iFirst To $iLast Using arrays doesn't change that. Case $InputBLD[0][0] To $InputBLD[$h][$v] Try it. I'm not guarenteeing anything here as this is more of a workaround, If you are unsure then the last thing to do is use the "Case Else" and go through a loop: $iMsg = GUIGetMsg() Switch $iMsg Case ... ; Normal Case statements Case Else For $x = 0 to $h For $y = 0 to $v If $iMsg = $InputBLD[$x][$y] Then do domething EndIf Next Next EndSwitch That is a foolproof method, but if you are working with a lot of buttons then it may be a bit slow, and may not look particularly pretty. I hope that somewhere there is the answer Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
AlmarM Posted November 8, 2010 Share Posted November 8, 2010 (edited) Global $aButtons[10][10] $hWnd = GUICreate("") For $y = 0 To UBound($aButtons) - 1 For $x = 0 To UBound($aButtons, 2) - 1 $aButtons[$y][$x] = GUICtrlCreateButton("", $x * 20, $y * 20, 20, 20) Next Next GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case -3 Exit Case $aButtons[0][0] To $aButtons[UBound($aButtons) - 1][UBound($aButtons, 2) - 1] For $_y = 0 To UBound($aButtons) - 1 For $_x = 0 To UBound($aButtons, 2) - 1 If ($iMsg = $aButtons[$_y][$_x]) Then MsgBox(0, "", "Button: " & $_y & ", " & $_x & " was pressed!") EndIf Next Next EndSwitch WEnd I'm at work, so I can't test this. This is hardcoded from my head. Try something like this. EDIT: Typo Edited November 8, 2010 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
marko001 Posted November 8, 2010 Author Share Posted November 8, 2010 @mat and @almarm Good results. I used the case else with nested for (2 dimensions array) and it works perfectly. Saved me hours of typing declaration of cases and buttons Thanks a lot for the precious help. Marco 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