Merrik Posted June 22, 2011 Share Posted June 22, 2011 (edited) I could use some help with this function. Two issues, first if you don't enter a name and click the button, it won't let you try again. Second if you enter a name, it keeps prompting for name. #include <GUIConstants.au3> HotKeySet("{enter}", "Click_Func") $widthCell=270 GUICreate(" My GUI input acceptfile", 220,120, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, 0x00000018); CtrlCreateLabel ("Name: ", 5, 30, $widthCell) $Name = GUICtrlCreateInput ( "", 100, 30, 100, 20) $ReadName = GuiCtrlRead($Name) $btn = GUICtrlCreateButton ("Ok", 100, 75, 80, 20) $clickonce = FalseGUISetState () While 1 $Data = GUIGetMsg() Select Case $Data = $Btn If $clickonce = False then Click_Func() EndIf Case $Data = $GUI_EVENT_CLOSE Exit EndSelect WEnd Func Click_Func() If $Name="" Then MsgBox(4096, "Error", "Please enter your name.") $clickonce = False Else MsgBox(0,"Name", "Your name is "& $ReadName) $clickonce = True Exit EndIf EndFunc Edited June 22, 2011 by Merrik Link to comment Share on other sites More sharing options...
hannes08 Posted June 22, 2011 Share Posted June 22, 2011 Hi Merrik, either move the line with "$Readname = GuiCtrlRead($Name)" before function call Click_Func() or move it to the first line of the function itself. Hint: Be careful when you mix global and local variables and handles. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
Merrik Posted June 22, 2011 Author Share Posted June 22, 2011 (edited) Thanks Hannes. This worked, but if I don't enter something, it won't let you try a second time. Also the message box error is always behind the enter name window. #include <GUIConstants.au3> HotKeySet("{enter}", "Click_Func") $widthCell=270 GUICreate(" My GUI input acceptfile", 220,120, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, 0x00000018); CtrlCreateLabel ("Name: ", 5, 30, $widthCell) $Name = GUICtrlCreateInput ( "", 100, 30, 100, 20) $btn = GUICtrlCreateButton ("Ok", 100, 75, 80, 20) $clickonce = False GUISetState (@SW_SHOW) While 1 $Data = GUIGetMsg() Select Case $Data = $Btn If $clickonce = False then Click_Func() EndIf Case $Data = $GUI_EVENT_CLOSE Exit EndSelect WEnd Func Click_Func() $ReadName = GuiCtrlRead($Name) If $Name="" Then MsgBox(4096, "Error", "Please enter your name.") $clickonce = False Else MsgBox(0,"Name", "Your name is "& $ReadName) $clickonce = True Exit EndIf EndFunc Edited June 22, 2011 by Merrik Link to comment Share on other sites More sharing options...
hannes08 Posted June 22, 2011 Share Posted June 22, 2011 Seems this works for me as it should... My MsgBox stays in front of the other window. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
Merrik Posted June 22, 2011 Author Share Posted June 22, 2011 Thanks Hannes for taking your time on this, but if I don't enter something in the input box, it won't let me try a second time. The input field is locked. I can click the button again only. Link to comment Share on other sites More sharing options...
monoscout999 Posted June 22, 2011 Share Posted June 22, 2011 ¿Did you close the MsgBox? Because this pause the script until is closed.By. MS999 Link to comment Share on other sites More sharing options...
Merrik Posted June 22, 2011 Author Share Posted June 22, 2011 Yes. The message box closes, but the Input box is not clickable. I can't enter anything. Link to comment Share on other sites More sharing options...
monoscout999 Posted June 22, 2011 Share Posted June 22, 2011 (edited) first i put the style of the Gui in a way to understand wich style it have #include <WindowsConstants.au3> 0x00000018 = bitor($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST) second i put the msgbox like child of the mainGUI so the Topmost style dont let the msgbox behind $GUI = GUICreate(" My GUI input acc..... ........ MsgBox(0,"Name", "Your name is "& $ReadName,0,$GUI) third i change this. If $Name="" Then ---> If NOT $ReadName Then The result is this. #include <GUIConstants.au3> #include <WindowsConstants.au3> HotKeySet("{enter}", "Click_Func") $widthCell=270 $GUI = GUICreate(" My GUI input acceptfile", 220,120, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, bitor($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST)); CtrlCreateLabel ("Name: ", 5, 30, $widthCell) $Name = GUICtrlCreateInput ( "", 100, 30, 100, 20) $btn = GUICtrlCreateButton ("Ok", 100, 75, 80, 20) $clickonce = False GUISetState (@SW_SHOW) While 1 $Data = GUIGetMsg() Select Case $Data = $Btn If $clickonce = False then Click_Func() EndIf Case $Data = $GUI_EVENT_CLOSE Exit EndSelect WEnd Func Click_Func() $ReadName = GuiCtrlRead($Name) If NOT $ReadName Then MsgBox(4096, "Error", "Please enter your name.",0,$GUI) $clickonce = False Else MsgBox(0,"Name", "Your name is "& $ReadName,0,$GUI) $clickonce = True Exit EndIf EndFunc Edited June 22, 2011 by monoscout999 Link to comment Share on other sites More sharing options...
Merrik Posted June 22, 2011 Author Share Posted June 22, 2011 (edited) Works great! Edited June 22, 2011 by Merrik 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