faldo Posted May 1, 2011 Posted May 1, 2011 (edited) Heya, I've made a GUI with a variable amount of buttons depending on the situation. I'll define that amount with a variable in my example for easy explanation. Since the amount of buttons varries, i have to use "Case $msg >= and $msg <=" in the GUIGetMsg() part of the script, according to the AutoIt help file. Here is the script: $Number_of_buttons = 20 $Button[1] For $i = 1 to $Number_of_buttons $Button[$i] = GUICtrlCreateButton("Button "&$i, 30, 20*$i, 120, 40) Next While 1 $msg = GUIGetMsg() Select Case $msg >= $Button[1] And $msg <= $Button[$Number_of_buttons] msgbox (0, "", "A button was pushed") EndSelect WEnd Now, the problem i've been getting is that sometimes i get a missmatch of controlIDs. Since i use >= <=, any controlID in between "$Button[1]" and "$Button[$Number_of_buttons]" will be triggered, even if the controlID doesn't belong to a button anymore due to some other GUI control taking that controlID. Is there another way to write the above code in order to avoid getting a missmatch? Edited May 1, 2011 by faldo Check out my other scripts: RDP antihammer/blacklist generator | Phemex cryptocurrency exchange API
Moderators SmOke_N Posted May 1, 2011 Moderators Posted May 1, 2011 Do you get it doing something like: Global $gi_max_buttons = 20 Global $ga_buttons[1] ReDim $ga_buttons[$gi_max_buttons] For $i = 0 To $gi_max_buttons - 1 $ga_buttons[$i] = GUICtrlCreateButton("Button " & $i, 30, 20 * $i, 120, 40) Next While 1 Switch GUIGetMsg() Case $ga_buttons[0] To $ga_buttons[$gi_max_buttons - 1] EndSwitch WEnd? 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.
Moderators SmOke_N Posted May 1, 2011 Moderators Posted May 1, 2011 (edited) Eh... this worked too using your select statement: Global $h_gui = GUICreate("", 170, 500) Global $gi_msg = 0 Global $gi_max_buttons = 20 Global $ga_buttons[1] ReDim $ga_buttons[$gi_max_buttons] For $i = 0 To $gi_max_buttons - 1 $ga_buttons[$i] = GUICtrlCreateButton("Button " & $i, 30, 25 * $i, 120, 25) Next GUISetState() While 1 $gi_msg = GUIGetMsg() Select Case $gi_msg = -3 Exit Case (($gi_msg >= $ga_buttons[0]) And ($gi_msg <= $ga_buttons[$gi_max_buttons -1])) ConsoleWrite("Button pushed...: " & $gi_msg & @CRLF) EndSelect WEnd So it's evident the code you're using ( which is obviously not this one you posted or else it'd error before you even got through the For/Next loop ), is having issues else where. Edited May 1, 2011 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.
faldo Posted May 2, 2011 Author Posted May 2, 2011 Thanx for your replies Smoke_n The issue was not that the code didn't work, but that elsewhere in the code, i'm unintentionally replacing the ControlIDs of the buttons in this example. I had hoped being able to resolve the issue with being more specific than using "$msg >= $Button[1] And $msg <= $Button[$Number_of_buttons]" complared to "$msg = $Button[1] OR $msg = $Button[2] OR $msg = $Button[3]..." Lets say $Button[1] = 13 and $Button[2] = 14 (as ControlIDs) If i delete $Button[2] and somehwere else in the code i create a checkbox, that checkbox can get a controlID of 14. When GUIGetMsg() then checks $msg and it returns 14, my Select-loop will think i've pushed button $Button[2] but in fact i've checked a checkbox. I hope i'm making sence at all Check out my other scripts: RDP antihammer/blacklist generator | Phemex cryptocurrency exchange API
AdmiralAlkex Posted May 2, 2011 Posted May 2, 2011 You could loop through the array (For-loop usually) and compare $gi_msg to the saved value. Why do you save the cId's if not for (something) like that? Something like: EndSelect For $iX to UBound() If $gi_msg = $array[$iX] then "button pushed" Next WEnd I don't have AutoIt here so I can't create a full example, but give it a try yourself, and I will check back later tonight. Also look at using OnEvent mode. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
faldo Posted May 2, 2011 Author Posted May 2, 2011 (edited) That's a great idea, i'll give it a try. Thanx a lot for the help! Edited May 2, 2011 by faldo Check out my other scripts: RDP antihammer/blacklist generator | Phemex cryptocurrency exchange API
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