Jump to content

Why BitAND(GUICtrlRead($idRadio1), $GUI_CHECKED) = $GUI_CHECKED instead of GUICtrlRead($idRadio1) = $GUI_CHECKED?


Go to solution Solved by Zedna,

Recommended Posts

I am always amazed by the eagerness of AutoIt experts to share their knowledge through this forum. Thank you all!
I have a question which may look silly to those who know the answer. If so, please pardon me.

Below is AutoIt Help example code on GUICtrlCreateRadio() function.
 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
GUICreate("My GUI radio") ; will create a dialog box that when displayed is centered

Local $idRadio1 = GUICtrlCreateRadio("Radio 1", 10, 10, 120, 20)
Local $idRadio2 = GUICtrlCreateRadio("Radio 2", 10, 40, 120, 20)
Local $idButton = GUICtrlCreateButton("Button", 150, 200, 100, 20)
;GUICtrlSetState($idRadio2, $GUI_CHECKED)

GUISetState(@SW_SHOW) ; will display an  dialog box with 1 checkbox

Local $idMsg
; Loop until the user exits.
While 1
    $idMsg = GUIGetMsg()
    Select
        Case $idMsg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $idMsg = $idRadio1 And BitAND(GUICtrlRead($idRadio1), $GUI_CHECKED) = $GUI_CHECKED
            MsgBox($MB_SYSTEMMODAL, 'Info:', 'You clicked the Radio 1 and it is Checked.')
        Case $idMsg = $idRadio2 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED
            MsgBox($MB_SYSTEMMODAL, 'Info:', 'You clicked on Radio 2 and it is Checked.')
    EndSelect
WEnd
EndFunc   ;==>Example

If I use GUICtrlRead($idRadio1) = $GUI_CHECKED instead of BitAND(GUICtrlRead($idRadio1), $GUI_CHECKED) = $GUI_CHECKED, will I be missing something?

Link to comment
Share on other sites

  • Solution

See https://www.autoitscript.com/wiki/FAQ#How_can_I_test_if_checkbox_/_radiobutton_is_checked?

 

In previous versions of AutoIt GUICtrlRead() returned more states (focused,disabled,...) so this approach with BitAnd() was the only one exactly correct.

In latest versions of AutoIt GUICtrlRead() returns only checked/unchecked states (and not others) so now (if you don't use older AutoIt's version) you can use simpler GUICtrlRead($control) = $GUI_CHECKED

Example of difference:

In older AutoIt if chekbox was checked and also disabled then GUICtrlRead($control) = $GUI_CHECKED returns FALSE

 

snippet from old AutoIt' helpfile for GUICtrlRead():

Quote

 

- for Checkbox/Radiostate returns state of the button, See State table

- For Checkbox, Radio control several states can be returned as $GUI_FOCUS and $GUI_CHECKED,. So use i.e. BitAnd(GUICtrlRead($Item),$GUI_CHECKED) to test if the control is checked.

 

 

snippet from new AutoIt' helpfile for GUICtrlRead():

Quote

 

- for Checkbox/Radiostate returns The checked state ($GUI_CHECKED or $GUI_UNCHECKED)

- 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.

 

 

Edited by Zedna
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...