batfastad Posted October 5, 2012 Posted October 5, 2012 (edited) Hi everyone I've got a collection of radio buttons and checkboxes. When a user presses some radio buttons I want to uncheck and disable a particular checkbox. This is easy, done by just summing the state flags... Func _RadioOutputPNGClick() If GUICtrlGetState($RadioOutputPNG) = $GUI_CHECKED Then ; PNG RADIO BUTTON CHECKED, TEXT PATHS CHECKBOX UNCHECK AND DISABLE GUICtrlSetState($CheckboxTextPaths, $GUI_UNCHECKED + $GUI_DISABLE) Else ; PNG RADIO BUTTON CHECKED, TEXT PATHS CHECKBOX CHECK AND ENABLE GUICtrlSetState($CheckboxTextPaths, $GUI_CHECKED + $GUI_ENABLE) EndIf EndFunc But when trying to assertain whether the radio button $RadioOutputPNG is checked or not, is my comparison above flawed if $RadioOutputPNG has another state flag set? Lets say $GUI_CHECKED = 1 and $GUI_DISABLE = 128 (from GUIConstantsEx.au3) and both are set for $RadioOutputPNG In my comparison above I'm basically checking whether $RadioOutputPNG = 1. Does this return false if both state flags are set, as the state of $RadioOutputPNG would actually be 129. So should I actually be doing a Bitwise comparison here? Cheers, B Edited October 5, 2012 by batfastad
batfastad Posted October 5, 2012 Author Posted October 5, 2012 (edited) Don't worry! Solved by RTFM!The answer is yes, I should do bitwise comparison...If BitAND(GUICtrlRead($RadioOutputPNG), $GUI_CHECKED) ThenEDIT:For completeness, if you want to check that a radio/checkbox is checked AND enabled then I think you need to do two different comparisons.I was expecting this to work but it doesn't...If BitAND(GUICtrlRead($CheckboxText), $GUI_CHECKED, $GUI_ENABLE) ThenBecause GUICtrlRead() doesn't return the state for checkboxes.Instead you have to additionally check GUICtrlGetState()...If BitAND(GUICtrlRead($CheckboxText), $GUI_CHECKED) AND BitAND(GUICtrlGetState($CheckboxText), $GUI_ENABLE) ThenThis is something that I just fell into because of the wording in the help under GUICtrlRead()... http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htmIn the table under the "Return Value" section, the "Checkbox, Radio" row has a link to this table of states... http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm#StateTableBy linking to that table in the return value on the GUICtrlRead() page, I assumed that all the items in that table of states would be valid return values for GUICtrlRead() but it turns out to not be the case.I'm not an expert so I might be wrong here and I would appreciate someone correcting me if I am wrong But I hope this helps someone out!Cheers, B Edited October 5, 2012 by batfastad armoros 1
blk_panther Posted June 9, 2016 Posted June 9, 2016 On 5.10.2012 at 4:50 PM, batfastad said: If BitAND(GUICtrlRead($CheckboxText), $GUI_CHECKED) Then Better use: If GUICtrlRead($CheckboxText) = $GUI_CHECKED Then
AutoBert Posted June 9, 2016 Posted June 9, 2016 It's not better just a other possible way, both did same for a checkbox: Quote For Checkbox and Radio controls only the $GUI_CHECKED (1), $GUI_UNCHECKED (4) or $GUI_INDETERMINATE (2) states are returned so the value can be used directly. so, why necroing a old thread?
blk_panther Posted June 9, 2016 Posted June 9, 2016 Because it's shorter and faster. And I don't want to leave the ones that come here in search for a solution with an inferior one.
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