Mecano Posted May 24, 2013 Posted May 24, 2013 Hallo forum members, Question? checkbox1 checked, input filled in, then Button1 active. I think this question is ask many times but the search results brings me further away. First start script works good, "Button1" is disabled, when input box is filled in "Button1" is still disabled, when $Checkbox1 is checked "Button1" is enabled so far so good. But when I uncheck $Checkbox1 "Button1" is still active! The script, forgot to tell that the script have to start up with $Checkbox1 checked. expandcollapse popup#NoTrayIcon #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #region ### START Koda GUI section ### $Form1 = GUICreate("Form1", 401, 193, 192, 124) $Input1 = GUICtrlCreateInput("", 120, 16, 160, 21) $Button1 = GUICtrlCreateButton("Button1", 120, 72, 160, 25) GUICtrlSetState($Button1, $GUI_DISABLE) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 122, 128, 97, 17) GUICtrlSetState($Checkbox1, $GUI_CheckED) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### $i = 1 While 1 If BitAnd(GUICtrlRead($Checkbox1),$GUI_UNCHECKED) = $GUI_UNCHECKED And GUICtrlRead($Input1) = "" And $i = 1 Then GUICtrlSetState($Button1, $GUI_DISABLE) $i = 0 MsgBox(0, "Unchecked", "Test unchecked", 10) Else If $i = 0 And BitAnd(GUICtrlRead($Checkbox1),$GUI_CHECKED) = $GUI_CHECKED And GUICtrlRead($Input1) <> "" Then GUICtrlSetState($Button1, $GUI_ENABLE) $i = 1 MsgBox(0, "Checked", "Test checked", 10) EndIf EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ; do your thing EndSwitch WEnd Part of the source Thanks in advance.
jdelaney Posted May 24, 2013 Posted May 24, 2013 (edited) works, now...this disables if not checked OR StringLen = 0...so enabled only when is checked, and stringlen>0 change to: StringLen(GUICtrlRead($Input1))>0...if you want only spaces to be able to enable the button as well #region ### START Koda GUI section ### $Form1 = GUICreate("Form1", 401, 193, 192, 124) $Input1 = GUICtrlCreateInput("", 120, 16, 160, 21) $Button1 = GUICtrlCreateButton("Button1", 120, 72, 160, 25) GUICtrlSetState($Button1, $GUI_DISABLE) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 122, 128, 97, 17) GUICtrlSetState($Checkbox1, $GUI_CheckED) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 If BitAnd(GUICtrlRead($Checkbox1),$GUI_CHECKED) And StringLen(StringSTripWS(GUICtrlRead($Input1),8))>0 Then If Not ControlCommand($Form1, "", $Button1, "IsEnabled") Then GUICtrlSetState($Button1, $GUI_ENABLE) Else If ControlCommand($Form1, "", $Button1, "IsEnabled") Then GUICtrlSetState($Button1, $GUI_DISABLE) EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ; do your thing EndSwitch WEnd Edited May 24, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Solution Neutro Posted May 24, 2013 Solution Posted May 24, 2013 (edited) Hello, You just needed to split this: If BitAnd(GUICtrlRead($Checkbox1),$GUI_UNCHECKED) = $GUI_UNCHECKED And GUICtrlRead($Input1) = "" And $i = 1 Then Into 2 seperate if statements: If GUICtrlRead($Input1) = "" And $button_enabled = 1 Then GUICtrlSetState($Button1, $GUI_DISABLE) $button_enabled = 0 Elseif BitAnd(GUICtrlRead($Checkbox1),$GUI_UNCHECKED) = $GUI_UNCHECKED and $button_enabled = 1 Then GUICtrlSetState($Button1, $GUI_DISABLE) $button_enabled = 0 Full code: expandcollapse popup#NoTrayIcon #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #region ### START Koda GUI section ### $Form1 = GUICreate("Form1", 401, 193, 192, 124) $Input1 = GUICtrlCreateInput("", 120, 16, 160, 21) $Button1 = GUICtrlCreateButton("Button1", 120, 72, 160, 25) GUICtrlSetState($Button1, $GUI_DISABLE) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 122, 128, 97, 17) GUICtrlSetState($Checkbox1, $GUI_CheckED) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### $button_enabled = 1 While 1 If GUICtrlRead($Input1) = "" And $button_enabled = 1 Then GUICtrlSetState($Button1, $GUI_DISABLE) $button_enabled = 0 Elseif BitAnd(GUICtrlRead($Checkbox1),$GUI_UNCHECKED) = $GUI_UNCHECKED and $button_enabled = 1 Then GUICtrlSetState($Button1, $GUI_DISABLE) $button_enabled = 0 ElseIf $button_enabled = 0 And BitAnd(GUICtrlRead($Checkbox1),$GUI_CHECKED) = $GUI_CHECKED And GUICtrlRead($Input1) <> "" Then GUICtrlSetState($Button1, $GUI_ENABLE) $button_enabled = 1 EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ; do your thing EndSwitch WEnd Edited May 24, 2013 by Neutro Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water!
jdelaney Posted May 24, 2013 Posted May 24, 2013 I'd stick with mine ...the above will have significant 'flashing' of the button, because he is not checking states prior to changing...also, mine has fewer blocks, and is easier to follow. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Neutro Posted May 24, 2013 Posted May 24, 2013 (edited) If you tried mine before posting, you would have seen that there is no "significant flashing" at all Your way of doing it is indeed shorter but I thought making only a few change to OP code would help him understand why his first code was not working PS: congratulations on your 1000th post Edited May 24, 2013 by Neutro Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water!
AdamUL Posted May 24, 2013 Posted May 24, 2013 (edited) Try this, and you should not have any button flicker. If StringStripWS(GUICtrlRead($Input1), 8) = "" OR BitAnd(GUICtrlRead($Checkbox1),$GUI_UNCHECKED) = $GUI_UNCHECKED And BitAND(GUICtrlGetState($Button1), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($Button1, $GUI_DISABLE) ElseIf StringStripWS(GUICtrlRead($Input1), 8) <> "" AND BitAnd(GUICtrlRead($Checkbox1),$GUI_CHECKED) = $GUI_CHECKED And BitAND(GUICtrlGetState($Button1), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Button1, $GUI_ENABLE) EndIf Edited May 26, 2013 by AdamUL
Mecano Posted May 25, 2013 Author Posted May 25, 2013 Hi all Thank you, it's working Universalist I didn't know this method something to study thx Neutro Thank you for explaining, en showing where I make the the mistake (good for my learning process) AdamUL Thanxs, if I fill input1 and checkbox1 is checked, button1 is enabled but when I uncheck checkbox1, button1 is still enabled
AdamUL Posted May 26, 2013 Posted May 26, 2013 (edited) Mecano, Sorry used a wrong operator, AND, instead of OR in the first part of the If statement. I have updated my post. The code should be work properly now. Edited May 26, 2013 by AdamUL
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