Jump to content

Button function


Recommended Posts

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
Link to comment
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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...