Sign in to follow this  
Followers 0
Merrik

Button function

9 posts in this topic

#1 ·  Posted (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 by Merrik

Share this post


Link to post
Share on other sites



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. :huh2:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by Merrik

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

¿Did you close the MsgBox? Because this pause the script until is closed.

By. MS999

Share this post


Link to post
Share on other sites

Yes. The message box closes, but the Input box is not clickable. I can't enter anything.

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by monoscout999

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Works great! :huh2:

Edited by Merrik

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0