Jump to content



Photo

Check if any checkbox in a window is checked?


  • Please log in to reply
3 replies to this topic

#1 benjbong

benjbong

    Seeker

  • Active Members
  • 34 posts

Posted 10 November 2011 - 05:58 PM

I have a gui window with a series of checkboxes created in an array as such:

$chkboxes[0] = GUICtrlCreateCheckbox($payers[0][0], -1 * $cellWidth, 0) $left = 1 For $i = 1 to UBound($payers) -1 Step 1 Select Case $left = 3 ;Edit this number to change the number of columns of check boxes   $chkboxes[$i] = Guictrlcreatecheckbox($payers[0][$i], -$left * $cellWidth, 0)   $left = 1 Case else ;Adds checkboxes to existing row until row limit is reached   $chkboxes[$i] = GUICtrlCreateCheckbox($payers[0][$i], 0, -1)   $left += 1 EndSelect Next


The checkbox array takes the elements of another array as the data and arranges them in columns. The form I have takes input from two other input boxes as well as at least 1 or more of these checkboxes and generates output when a button is pressed. I'm trying to set up form validation to make sure the user can't press the generate button until both input boxes are filled in and at least one of the checkboxes is checked.

I use a Do.. While loop to check watch for various GUIGetMsg events such as when other buttons are pressed to perform an action. How can i add something to that loop that will check when ANY checkbox is added to enable/disable the generate button accordingly?







#2 benjbong

benjbong

    Seeker

  • Active Members
  • 34 posts

Posted 10 November 2011 - 07:29 PM

Here's the solution, if anybody was wondering. You basically monitor GUIGetMsg() to see if it contains a member of the array as such:

Do     $msg = GUIGetMsg()     Select         Case $msg >= $chkboxes[0] and $msg <= $chkboxes[ubound($chkboxes) -1] Until $msg = $GUI_EVENT_CLOSE


#3 somdcomputerguy

somdcomputerguy

  • Active Members
  • PipPipPipPipPipPip
  • 2,414 posts

Posted 10 November 2011 - 07:29 PM

This code - If BitAnd(GUICtrlRead($Checkbox), $GUI_CHECKED) Then, can be used to check if a checkbox is checked.
- Bruce /* somdcomputerguy */If you change the way you look at things, the things you look at change.

#4 sleepydvdr

sleepydvdr

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 572 posts

Posted 10 November 2011 - 07:43 PM

I was thinking of a different way of doing it. With the example below, after checking one of the checkboxes, you must click somewhere in the gui to run a function that detects if any of the checkboxes are checked. The only problem with it is not being able to detect changes to the checkboxes directly.

AutoIt         
#include <GUIConstants.au3> #include <WindowsConstants.au3> Global $check1, $Checkbox1, $Checkbox2, $Checkbox3 GUIRegisterMsg($WM_LBUTTONDOWN, "_CheckForChange") $Form1 = GUICreate("Form1", 294, 152) $Button1 = GUICtrlCreateButton("Validate", 160, 48, 75, 25, 0) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 32, 32, 97, 17) $Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 32, 56, 97, 17) $Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 32, 80, 97, 17) GUISetState(@SW_SHOW) GUICtrlSetState($Button1, $GUI_DISABLE) While 1     $nMsg = GUIGetMsg()     Switch $nMsg         Case $GUI_EVENT_CLOSE             Exit                Case $Button1             MsgBox(0, "", $check1)     EndSwitch WEnd Func _CheckForChange()     $check1 = GUICtrlRead($Checkbox1)     $check2 = GUICtrlRead($Checkbox2)     $check3 = GUICtrlRead($Checkbox3)     If $check1 > 1 OR $check2 > 1 OR $check3 > 1 Then         GUICtrlSetState($Button1, $GUI_ENABLE)     Endif EndFunc

#include <ByteMe.au3>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users