HockeyFan Posted January 8, 2007 Posted January 8, 2007 Novice scripter here again! :"> Can someone help me with testing the condition of a GUI Input to make sure it not empty?? I have a GUI window that I want user's to enter their first and last name, but I want the OK button disabled until the last name input box is filled out. I also would like the OK button to be disabled again if the text in the Input box is cleared out. This is what I have so far and it works up until the point where I clear the last name input box after typing text into it for the first time. expandcollapse popup#include <GuiConstants.au3> Opt("GUIOnEventMode", 1) $font = "Arial Bold" WinMinimizeAll() GuiCreate("", 400, 316,-1, -1, $WS_EX_TOPMOST) GUISetBkColor (0xFFFFFF) $GUIMainText = GuiCtrlCreateLabel("Please type the following information: ", 20, 20, 350, 30) GUICtrlSetFont(-1, 14, 400, 0, $font) GUICtrlSetColor ($GUIMainText, 0xFF0000) $LabelFirstName = GuiCtrlCreateLabel("First Name:", 20, 70, 350, 20) GUICtrlSetFont(-1, 12, 400, 0, $font) $InputFirstName = GuiCtrlCreateInput("", 20, 90, 350, 30) GUICtrlSetFont(-1, 12, 400, 0, $font) GUICtrlSetColor ($InputFirstName, 0x0033FF) $LabelLastName = GuiCtrlCreateLabel("Last Name:", 20, 140, 350, 20) GUICtrlSetFont(-1, 12, 400, 0, $font) $InputlastName = GuiCtrlCreateInput("", 20, 160, 350, 30) GUICtrlSetFont(-1, 12, 400, 0, $font) GUICtrlSetColor ($InputlastName, 0x0033FF) $OKButton6 = GuiCtrlCreateButton("OK", 135, 225, 120, 30) GUICtrlSetOnEvent($OKButton6, "OKButton") GuiSetState(@SW_SHOW) ControlDisable("", "OK", 8) While 1 $msg = GUIGetMsg() $TypedName = GUICtrlRead($InputlastName) Do Sleep(100) $TypedName = GUICtrlRead($InputlastName) Until $TypedName <> "" ControlEnable("", "OK", 8) WEnd Func OKButton() Exit EndFunc Would someone be so kind to assist me with how to make this happen? Thank you!
GaryFrost Posted January 8, 2007 Posted January 8, 2007 expandcollapse popup#include <GuiConstants.au3> #include <Misc.au3> Opt("GUIOnEventMode", 1) $font = "Arial Bold" WinMinimizeAll() GUICreate("", 400, 316, -1, -1, $WS_EX_TOPMOST) GUISetBkColor(0xFFFFFF) $GUIMainText = GUICtrlCreateLabel("Please type the following information: ", 20, 20, 350, 30) GUICtrlSetFont(-1, 14, 400, 0, $font) GUICtrlSetColor($GUIMainText, 0xFF0000) $LabelFirstName = GUICtrlCreateLabel("First Name:", 20, 70, 350, 20) GUICtrlSetFont(-1, 12, 400, 0, $font) $InputFirstName = GUICtrlCreateInput("", 20, 90, 350, 30) GUICtrlSetFont(-1, 12, 400, 0, $font) GUICtrlSetColor($InputFirstName, 0x0033FF) $LabelLastName = GUICtrlCreateLabel("Last Name:", 20, 140, 350, 20) GUICtrlSetFont(-1, 12, 400, 0, $font) $InputlastName = GUICtrlCreateInput("", 20, 160, 350, 30) GUICtrlSetFont(-1, 12, 400, 0, $font) GUICtrlSetColor($InputlastName, 0x0033FF) $OKButton6 = GUICtrlCreateButton("OK", 135, 225, 120, 30) GUICtrlSetOnEvent($OKButton6, "OKButton") GUICtrlSetState($OKButton6, $GUI_DISABLE) GUISetState() While 1 Sleep(10) $TypedName = GUICtrlRead($InputlastName) If $TypedName <> "" And BitAND(GUICtrlGetState($OKButton6), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($OKButton6, $GUI_ENABLE) ElseIf $TypedName = "" And BitAND(GUICtrlGetState($OKButton6), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($OKButton6, $GUI_DISABLE) EndIf WEnd Exit Func OKButton() Exit EndFunc ;==>OKButton SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference. Â
HockeyFan Posted January 8, 2007 Author Posted January 8, 2007 jafrost, Thank you SOOOO much for you help! Once again you have been a tremendous help! Thank you!!
HockeyFan Posted January 9, 2007 Author Posted January 9, 2007 expandcollapse popup#include <GuiConstants.au3> #include <Misc.au3> Opt("GUIOnEventMode", 1) $font = "Arial Bold" WinMinimizeAll() GUICreate("", 400, 316, -1, -1, $WS_EX_TOPMOST) GUISetBkColor(0xFFFFFF) $GUIMainText = GUICtrlCreateLabel("Please type the following information: ", 20, 20, 350, 30) GUICtrlSetFont(-1, 14, 400, 0, $font) GUICtrlSetColor($GUIMainText, 0xFF0000) $LabelFirstName = GUICtrlCreateLabel("First Name:", 20, 70, 350, 20) GUICtrlSetFont(-1, 12, 400, 0, $font) $InputFirstName = GUICtrlCreateInput("", 20, 90, 350, 30) GUICtrlSetFont(-1, 12, 400, 0, $font) GUICtrlSetColor($InputFirstName, 0x0033FF) $LabelLastName = GUICtrlCreateLabel("Last Name:", 20, 140, 350, 20) GUICtrlSetFont(-1, 12, 400, 0, $font) $InputlastName = GUICtrlCreateInput("", 20, 160, 350, 30) GUICtrlSetFont(-1, 12, 400, 0, $font) GUICtrlSetColor($InputlastName, 0x0033FF) $OKButton6 = GUICtrlCreateButton("OK", 135, 225, 120, 30) GUICtrlSetOnEvent($OKButton6, "OKButton") GUICtrlSetState($OKButton6, $GUI_DISABLE) GUISetState() While 1 Sleep(10) $TypedName = GUICtrlRead($InputlastName) If $TypedName <> "" And BitAND(GUICtrlGetState($OKButton6), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($OKButton6, $GUI_ENABLE) ElseIf $TypedName = "" And BitAND(GUICtrlGetState($OKButton6), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($OKButton6, $GUI_DISABLE) EndIf WEnd Exit Func OKButton() Exit EndFunc ;==>OKButton gafrost, Sorry to bother you, - :"> but I was wondering if you could assist me again with my script. Yesterday you helped me with testing the condition of a GUI Input to make sure it wasn't empty. I now need to test both (frist name & last name) Input boxes to make sure they are not empty before enableing the OK button. I've played around with it for a while but I am not able to make it work. Is this something you would help me with...please!
GaryFrost Posted January 10, 2007 Posted January 10, 2007 (edited) expandcollapse popup#include <GuiConstants.au3> Global Const $WM_COMMAND = 0x0111 Global Const $EN_CHANGE = 0x300 Global Const $DebugIt = 1 Opt("GUIOnEventMode", 1) $font = "Arial Bold" WinMinimizeAll() GUICreate("", 400, 316, -1, -1, $WS_EX_TOPMOST) GUISetBkColor(0xFFFFFF) $GUIMainText = GUICtrlCreateLabel("Please type the following information: ", 20, 20, 350, 30) GUICtrlSetFont(-1, 14, 400, 0, $font) GUICtrlSetColor($GUIMainText, 0xFF0000) $LabelFirstName = GUICtrlCreateLabel("First Name:", 20, 70, 350, 20) GUICtrlSetFont(-1, 12, 400, 0, $font) $InputFirstName = GUICtrlCreateInput("", 20, 90, 350, 30) GUICtrlSetFont(-1, 12, 400, 0, $font) GUICtrlSetColor($InputFirstName, 0x0033FF) $LabelLastName = GUICtrlCreateLabel("Last Name:", 20, 140, 350, 20) GUICtrlSetFont(-1, 12, 400, 0, $font) $InputlastName = GUICtrlCreateInput("", 20, 160, 350, 30) GUICtrlSetFont(-1, 12, 400, 0, $font) GUICtrlSetColor($InputlastName, 0x0033FF) $OKButton6 = GUICtrlCreateButton("OK", 135, 225, 120, 30) GUICtrlSetOnEvent($OKButton6, "OKButton") GUICtrlSetState($OKButton6, $GUI_DISABLE) GUISetState() GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") While 1 Sleep(10) WEnd Func OKButton() Exit EndFunc ;==>OKButton Func _Terminate() Exit EndFunc ;==>_Terminate Func _FirstName_Changed() ;---------------------------------------------------------------------------------------------- If $DebugIt Then _DebugPrint("_FirstName_Changed:" & GUICtrlRead($InputFirstName)) ;---------------------------------------------------------------------------------------------- _CheckNames() EndFunc ;==>_FirstName_Changed Func _LastName_Changed() ;---------------------------------------------------------------------------------------------- If $DebugIt Then _DebugPrint("_LastName_Changed:" & GUICtrlRead($InputlastName)) ;---------------------------------------------------------------------------------------------- _CheckNames() EndFunc ;==>_LastName_Changed Func _CheckNames() $TypedFName = GUICtrlRead($InputlastName) $TypedLName = GUICtrlRead($InputlastName) If $TypedFName <> "" And $TypedLName <> "" And BitAND(GUICtrlGetState($OKButton6), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($OKButton6, $GUI_ENABLE) ElseIf $TypedFName = "" And $TypedLName = "" And BitAND(GUICtrlGetState($OKButton6), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($OKButton6, $GUI_DISABLE) EndIf EndFunc ;==>_CheckNames Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0xFFFF) Local $hCtrl = $lParam Switch $nID Case $InputFirstName Switch $nNotifyCode Case $EN_CHANGE _FirstName_Changed() EndSwitch Case $InputlastName Switch $nNotifyCode Case $EN_CHANGE _LastName_Changed() EndSwitch EndSwitch ; Proceed the default Autoit3 internal message commands. ; You also can complete let the line out. ; !!! But only 'Return' (without any value) will not proceed ; the default Autoit3-message in the future !!! Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_COMMAND Func _DebugPrint($s_text) $s_text = StringReplace($s_text, @LF, @LF & "-->") ConsoleWrite("!===========================================================" & @LF & _ "+===========================================================" & @LF & _ "-->" & $s_text & @LF & _ "+===========================================================" & @LF) EndFunc ;==>_DebugPrint Edited January 10, 2007 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference. Â
HockeyFan Posted January 10, 2007 Author Posted January 10, 2007 Thank You! ...but WOW!!! This is really confusing stuff! I didn't think something that seemed so simple would be so confusing. None the less, thank you again for your help.
Uten Posted January 10, 2007 Posted January 10, 2007 Hehe..@gafrost gave you the pro version. Although with a tiny bug for you to figure out You could also do something like this. But, that would be the scripters quick fix version. While 1 Sleep(10) if (GUICtrlRead($InputlastName) <> "") AND (GUICtrlRead($InputFirstName) <> "") AND (BitAND(GUICtrlGetState($OKButton6), $GUI_DISABLE) = $GUI_DISABLE) Then GUICtrlSetState($OKButton6, $GUI_ENABLE) ElseIf ((GUICtrlRead($InputlastName) <> "") OR (GUICtrlRead($InputFirstName) = "")) AND (BitAND(GUICtrlGetState($OKButton6), $GUI_ENABLE) = $GUI_ENABLE) Then GUICtrlSetState($OKButton6, $GUI_DISABLE) EndIf WEnd Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
HockeyFan Posted January 12, 2007 Author Posted January 12, 2007 (edited) Hehe..@gafrost gave you the pro version. Although with a tiny bug for you to figure out You could also do something like this. But, that would be the scripters quick fix version. While 1 Sleep(10) if (GUICtrlRead($InputlastName) <> "") AND (GUICtrlRead($InputFirstName) <> "") AND (BitAND(GUICtrlGetState($OKButton6), $GUI_DISABLE) = $GUI_DISABLE) Then GUICtrlSetState($OKButton6, $GUI_ENABLE) ElseIf ((GUICtrlRead($InputlastName) <> "") OR (GUICtrlRead($InputFirstName) = "")) AND (BitAND(GUICtrlGetState($OKButton6), $GUI_ENABLE) = $GUI_ENABLE) Then GUICtrlSetState($OKButton6, $GUI_DISABLE) EndIf WEnd I get jokes... Uten, Thanks for the input ...but when I use your suggestion, the OK button flickers enabled/disabled. What can i do about that? Edited January 12, 2007 by HockeyFan
Uten Posted January 13, 2007 Posted January 13, 2007 :"> Probably because there was a small unfortunate copy paste bug in the disable part of the test. Compare with this code. Func testFlickerButtons() $gui = GuiCreate("testFlickerbuttons",230, 70) $lbl1 = GUICtrlCreateInput("", 10, 10, 100, 21) $lbl2 = GUICtrlCreateInput("", 115, 10, 100, 21) $btn1 = GUICtrlCreateButton("OK", 100, 36, 30) GUISetState(@SW_SHOW) Sleep(1000) While 1 $msg = guiGetMsg() If $msg = -3 Then ExitLoop if (GUICtrlRead($lbl1) <> "") AND (GUICtrlRead($lbl2) <> "") AND (BitAND(GUICtrlGetState($btn1), $GUI_DISABLE) = $GUI_DISABLE) Then GUICtrlSetState($btn1, $GUI_ENABLE) dbg("enable") ElseIf ((GUICtrlRead($lbl1) = "") OR (GUICtrlRead($lbl1) = "")) AND (BitAND(GUICtrlGetState($btn1), $GUI_ENABLE) = $GUI_ENABLE) Then GUICtrlSetState($btn1, $GUI_DISABLE) dbg("disable") Else dbg("nothing") Sleep(100) EndIf WEnd EndFunc Func dbg($msg, $error = @error, $extended = @extended, $erl = @ScriptLineNumber) ConsoleWrite("(" & $erl & ") : = (" & $error & ")(" & $extended & ") " & $msg & @LF) Return $error EndFunc ;==>dbg testFlickerButtons() exit NOTE: If you understand @garys code, it is probably better to use that. The quick dirty think I have provided will probably consume a lot more CPU. So it all boils down to your millage and what you intend to use the code for, Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
HockeyFan Posted January 16, 2007 Author Posted January 16, 2007 :"> Probably because there was a small unfortunate copy paste bug in the disable part of the test. Compare with this code. Func testFlickerButtons() $gui = GuiCreate("testFlickerbuttons",230, 70) $lbl1 = GUICtrlCreateInput("", 10, 10, 100, 21) $lbl2 = GUICtrlCreateInput("", 115, 10, 100, 21) $btn1 = GUICtrlCreateButton("OK", 100, 36, 30) GUISetState(@SW_SHOW) Sleep(1000) While 1 $msg = guiGetMsg() If $msg = -3 Then ExitLoop if (GUICtrlRead($lbl1) <> "") AND (GUICtrlRead($lbl2) <> "") AND (BitAND(GUICtrlGetState($btn1), $GUI_DISABLE) = $GUI_DISABLE) Then GUICtrlSetState($btn1, $GUI_ENABLE) dbg("enable") ElseIf ((GUICtrlRead($lbl1) = "") OR (GUICtrlRead($lbl1) = "")) AND (BitAND(GUICtrlGetState($btn1), $GUI_ENABLE) = $GUI_ENABLE) Then GUICtrlSetState($btn1, $GUI_DISABLE) dbg("disable") Else dbg("nothing") Sleep(100) EndIf WEnd EndFunc Func dbg($msg, $error = @error, $extended = @extended, $erl = @ScriptLineNumber) ConsoleWrite("(" & $erl & ") : = (" & $error & ")(" & $extended & ") " & $msg & @LF) Return $error EndFunc ;==>dbg testFlickerButtons() exit NOTE: If you understand @garys code, it is probably better to use that. The quick dirty think I have provided will probably consume a lot more CPU. So it all boils down to your millage and what you intend to use the code for, Uten, Thanks for the example. I reworked it and put it in my script and everything is working great. Thanks for the help.
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