HockeyFan Posted January 12, 2009 Share Posted January 12, 2009 (edited) Help! I'm attempting to check the status of two GUI controls to determine if the OK Button is to be enabled or not. So far it's not working. What I want to do is test the status of the InputBox and the Checkbox...if the InputBox is NOT "blank", or the CheckBox is "Checked"; enable the "OK" button. If the InputBox is NOT blank, the OK button is enabled. If the CheckBox is enabled, the OK button can be enabled and the InputBox is then disabled. Also, if the CheckBox is "unchecked", the InputBox is "enabled", but if the InputBox is "Blank" the OK button is not enabled until text is entered into the InputBox. Clear as mud, right? The problem so far is that I am not getting the OK buttun to enable if I check the CheckBox. I know this is because of the IF statement checking the status of the InputBox when it is blank. How can this be coded to work the way I want it to? Here is what I have so far... expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $UserNameInputGUI = GUICreate("", 500, 305, -1, -1, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS)) $UserNameLabel1 = GUICtrlCreateLabel("Please enter the User's Name: (Full First and Last Name)", 8, 8, 580, 41, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xff0000);Red $UserNameInput = GUICtrlCreateInput("", 8, 50, 480, 28) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $UserNameLabel2 = GUICtrlCreateLabel("( Example: John Doe )", 12, 85, 364, 17) $NoUserNameGroup = GUICtrlCreateGroup("Temp and Volunteer Staff", 8, 120, 480, 120) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $NoUserSelectLabel = GUICtrlCreateLabel('If there is "NO" employee associated with this computer,' & @CRLF & "please check the box below:", 24, 144, 460, 50) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x0000ff);Blue $TempVolCheckbox = GUICtrlCreateCheckbox(" Temp / Volunteer User", 72, 200, 220, 17) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xffff00);Yellow GUICtrlCreateGroup("", -99, -99, 1, 1) $UserNameOKButton = GUICtrlCreateButton("OK", 200, 255, 100, 35, 0) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") GUICtrlSetState ($UserNameOKButton, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() If GUICtrlRead ($UserNameInput) = "" Then GUICtrlSetState ($UserNameOKButton, $GUI_DISABLE) If GUICtrlRead ($UserNameInput) <> "" Then GUICtrlSetState ($UserNameOKButton, $GUI_ENABLE) Sleep(40); Idle around Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $TempVolCheckbox If BitAND(GUICtrlRead($TempVolCheckbox), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState ($UserNameInput, $GUI_DISABLE) GUICtrlSetState ($UserNameOKButton, $GUI_ENABLE) Else GUICtrlSetState ($UserNameInput, $GUI_ENABLE) EndIf EndSwitch WEnd Edited January 12, 2009 by HockeyFan Link to comment Share on other sites More sharing options...
evilertoaster Posted January 12, 2009 Share Posted January 12, 2009 Just a matter of making sure your logic triggers the way you want. Here's one way to do it- expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $UserNameInputGUI = GUICreate("", 500, 305, -1, -1, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS)) $UserNameLabel1 = GUICtrlCreateLabel("Please enter the User's Name: (Full First and Last Name)", 8, 8, 580, 41, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xff0000);Red $UserNameInput = GUICtrlCreateInput("", 8, 50, 480, 28) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $UserNameLabel2 = GUICtrlCreateLabel("( Example: John Doe )", 12, 85, 364, 17) $NoUserNameGroup = GUICtrlCreateGroup("Temp and Volunteer Staff", 8, 120, 480, 120) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $NoUserSelectLabel = GUICtrlCreateLabel('If there is "NO" employee associated with this computer,' & @CRLF & "please check the box below:", 24, 144, 460, 50) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x0000ff);Blue $TempVolCheckbox = GUICtrlCreateCheckbox(" Temp / Volunteer User", 72, 200, 220, 17) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xffff00);Yellow GUICtrlCreateGroup("", -99, -99, 1, 1) $UserNameOKButton = GUICtrlCreateButton("OK", 200, 255, 100, 35, 0) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") GUICtrlSetState ($UserNameOKButton, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 Sleep(50) if GUIGetMsg()=$GUI_EVENT_CLOSE then Exit if GUICtrlRead($TempVolCheckbox)=1 Then GUICtrlSetState($UserNameOKButton,$GUI_ENABLE) else GUICtrlSetState($UserNameOKButton,$GUI_DISABLE) endif if GUICtrlRead($UserNameInput)<>"" Then GUICtrlSetState($UserNameOKButton,$GUI_ENABLE) else if GUICtrlRead($TempVolCheckbox)=4 Then GUICtrlSetState($UserNameOKButton,$GUI_DISABLE) EndIf WEnd Link to comment Share on other sites More sharing options...
Valuater Posted January 12, 2009 Share Posted January 12, 2009 That's not it evil... nice try!!! 8) Link to comment Share on other sites More sharing options...
evilertoaster Posted January 12, 2009 Share Posted January 12, 2009 (edited) It's not? Erhm...gimme a sec to get AutoIt and test it out...It looked to good to me~ Edit: I didn't disable the input, (I hope that's what you meant valuater) use this for the loop- While 1 Sleep(50) if GUIGetMsg()=$GUI_EVENT_CLOSE then Exit if GUICtrlRead($TempVolCheckbox)=1 Then GUICtrlSetState($UserNameOKButton,$GUI_ENABLE) GUICtrlSetState($UserNameInput,$GUI_DISABLE) else GUICtrlSetState($UserNameOKButton,$GUI_DISABLE) GUICtrlSetState($UserNameInput,$GUI_ENABLE) endif if GUICtrlRead($UserNameInput)<>"" Then GUICtrlSetState($UserNameOKButton,$GUI_ENABLE) else if GUICtrlRead($TempVolCheckbox)=4 Then GUICtrlSetState($UserNameOKButton,$GUI_DISABLE) EndIf WEnd That's all I got I think... Edited January 12, 2009 by evilertoaster Link to comment Share on other sites More sharing options...
HockeyFan Posted January 12, 2009 Author Share Posted January 12, 2009 Just a matter of making sure your logic triggers the way you want. Here's one way to do it- expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $UserNameInputGUI = GUICreate("", 500, 305, -1, -1, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS)) $UserNameLabel1 = GUICtrlCreateLabel("Please enter the User's Name: (Full First and Last Name)", 8, 8, 580, 41, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xff0000);Red $UserNameInput = GUICtrlCreateInput("", 8, 50, 480, 28) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $UserNameLabel2 = GUICtrlCreateLabel("( Example: John Doe )", 12, 85, 364, 17) $NoUserNameGroup = GUICtrlCreateGroup("Temp and Volunteer Staff", 8, 120, 480, 120) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $NoUserSelectLabel = GUICtrlCreateLabel('If there is "NO" employee associated with this computer,' & @CRLF & "please check the box below:", 24, 144, 460, 50) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x0000ff);Blue $TempVolCheckbox = GUICtrlCreateCheckbox(" Temp / Volunteer User", 72, 200, 220, 17) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xffff00);Yellow GUICtrlCreateGroup("", -99, -99, 1, 1) $UserNameOKButton = GUICtrlCreateButton("OK", 200, 255, 100, 35, 0) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") GUICtrlSetState ($UserNameOKButton, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 Sleep(50) if GUIGetMsg()=$GUI_EVENT_CLOSE then Exit if GUICtrlRead($TempVolCheckbox)=1 Then GUICtrlSetState($UserNameOKButton,$GUI_ENABLE) else GUICtrlSetState($UserNameOKButton,$GUI_DISABLE) endif if GUICtrlRead($UserNameInput)<>"" Then GUICtrlSetState($UserNameOKButton,$GUI_ENABLE) else if GUICtrlRead($TempVolCheckbox)=4 Then GUICtrlSetState($UserNameOKButton,$GUI_DISABLE) EndIf WEnd Thanks...I'll give a try! Link to comment Share on other sites More sharing options...
HockeyFan Posted January 12, 2009 Author Share Posted January 12, 2009 It's not? Erhm...gimme a sec to get AutoIt and test it out...It looked to good to me~ Edit: I didn't disable the input, (I hope that's what you meant valuater) use this for the loop- While 1 Sleep(50) if GUIGetMsg()=$GUI_EVENT_CLOSE then Exit if GUICtrlRead($TempVolCheckbox)=1 Then GUICtrlSetState($UserNameOKButton,$GUI_ENABLE) GUICtrlSetState($UserNameInput,$GUI_DISABLE) else GUICtrlSetState($UserNameOKButton,$GUI_DISABLE) GUICtrlSetState($UserNameInput,$GUI_ENABLE) endif if GUICtrlRead($UserNameInput)<>"" Then GUICtrlSetState($UserNameOKButton,$GUI_ENABLE) else if GUICtrlRead($TempVolCheckbox)=4 Then GUICtrlSetState($UserNameOKButton,$GUI_DISABLE) EndIf WEnd That's all I got I think... That's it!! Thank you so much! Link to comment Share on other sites More sharing options...
Valuater Posted January 13, 2009 Share Posted January 13, 2009 (edited) Man, I should have never started on this one... I worked my but off trying to get it ( just a Hobbyist .. lol ) THIS WILL ALLOW YOU TO USE THE LOOP TO GET A MESSAGE ... AND HELPS TO STOP FLICKERING!!! expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Dim $Enable = 0 $UserNameInputGUI = GUICreate("", 500, 305, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS)) $UserNameLabel1 = GUICtrlCreateLabel("Please enter the User's Name: (Full First and Last Name)", 8, 8, 580, 41, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xff0000);Red $UserNameInput = GUICtrlCreateInput("", 8, 50, 480, 28) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $UserNameLabel2 = GUICtrlCreateLabel("( Example: John Doe )", 12, 85, 364, 17) $NoUserNameGroup = GUICtrlCreateGroup("Temp and Volunteer Staff", 8, 120, 480, 120) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $NoUserSelectLabel = GUICtrlCreateLabel('If there is "NO" employee associated with this computer,' & @CRLF & "please check the box below:", 24, 144, 460, 50) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x0000ff);Blue $TempVolCheckbox = GUICtrlCreateCheckbox(" Temp / Volunteer User", 72, 200, 220, 17) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xffff00);Yellow GUICtrlCreateGroup("", -99, -99, 1, 1) $UserNameOKButton = GUICtrlCreateButton("OK", 200, 255, 100, 35, 0) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") GUICtrlSetState($UserNameOKButton, $GUI_DISABLE) GUISetState(@SW_SHOW) AdlibEnable("Test_Input", 200) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $UserNameOKButton ;AdlibDisable() MsgBox(4096, "Test", "OK... ", 3) EndSwitch WEnd Func Test_Input() Local $checked = BitAND(GUICtrlRead($TempVolCheckbox), $GUI_CHECKED) = $GUI_CHECKED If GUICtrlRead($UserNameInput) = "" Then If $Enable = 0 And $checked Then GUICtrlSetState($UserNameInput, $GUI_DISABLE) GUICtrlSetState($UserNameOKButton, $GUI_ENABLE) $Enable = 1 ElseIf $Enable = 1 And Not $checked Then GUICtrlSetState($TempVolCheckbox, $GUI_ENABLE) GUICtrlSetState($UserNameInput, $GUI_ENABLE) GUICtrlSetState($UserNameOKButton, $GUI_DISABLE) $Enable = 0 EndIf Else If $Enable = 0 Then GUICtrlSetState($TempVolCheckbox, $GUI_UNCHECKED) GUICtrlSetState($TempVolCheckbox, $GUI_DISABLE) GUICtrlSetState($UserNameOKButton, $GUI_ENABLE) $Enable = 1 EndIf EndIf EndFunc ;==>Test_Input 8) Edited January 13, 2009 by Valuater Link to comment Share on other sites More sharing options...
DarkBoost Posted January 20, 2009 Share Posted January 20, 2009 For myself currently learning GUI I found this very educational, however I would like to ask how is the Func Test_Input() being executed without being called? Link to comment Share on other sites More sharing options...
BrettF Posted January 20, 2009 Share Posted January 20, 2009 With this function: AdlibEnable("Test_Input", 200) Have a look in the helpfile for it Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
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