Jump to content

$GUIGetMsg() not accepting user input?


Recommended Posts

I have 2 important snippets of code that aren't working. I am making a window that asks for user input and names that user input $user_input. When I run my script I get a window that has a text box and a submit button. Problem is that when I enter data and hit either enter or the submit button I dont get the MsgBox that displays what I types in the text box. Can someone help me please?

$Form1 = GUICreate("AForm1", 400, 229, 193, 115); creats a GUI window (Width, Height, Left, Top,)
$edit_field = GUICtrlCreateInput("", 40, 52, 245, 21); creats a blank textbox in the GUI window 
$btn_test = GUICtrlCreateButton("Submit", 308, 52, 75, 21, 0); creates a button labeled Submit in the GUI window
GUISetState(@SW_SHOW); shows the GUI window? Found reference to @SW_HIDE

and

Func Get_user_input()
    While 1; loop get user input 
        WinActivate("Barcode.exe"); Makes the Barcode.exe process the active process
        $user_input = GUIGetMsg(); get input from the user and declare the data as $user_input
            Switch $user_input
                Case $GUI_EVENT_CLOSE; If the GUI is closed then the loop goes to the next line and "exits"
                    Exit; exit loop
            EndSwitch
    WEnd
EndFunc

If $user_input > 0 Then
    MsgBox(0, $user_input, $user_input)
EndIf

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Not sure whether you were trying to go for an OnEvent mode or what, but this is sort of the basic way to do what you're after

#include <guiConstants.au3>
$Form1 = GUICreate("AForm1", 400, 229, 193, 115); creats a GUI window (Width, Height, Left, Top,)
$edit_field = GUICtrlCreateInput("", 40, 52, 245, 21); creats a blank textbox in the GUI window
$btn_test = GUICtrlCreateButton("Submit", 308, 52, 75, 21, 0); creates a button labeled Submit in the GUI window
GUISetState(@SW_SHOW); shows the GUI window? Found reference to @SW_HIDE

While 1; loop to get Gui msg
    WinActivate("Barcode.exe"); Makes the Barcode.exe process the active process
    $msg= GUIGetMsg(); poll the Gui for events
    Switch $msg
        Case $GUI_EVENT_CLOSE; If the GUI is closed then the loop goes to the next line and "exits"
            Exit; exit loop
        Case $btn_test ; If the submit buuton is pressed then 
            $user_input = GUICtrlRead($edit_field) ; read the input from the box and declare the data as $user_input
            MsgBox(0,"user input",$user_input)
    EndSwitch
WEnd
Link to comment
Share on other sites

OK I got it to output the message but it doesn't read the input in its entirety. For instance I type in 123 and the msgbox states just the 3. Heres the working code.

Func Get_user_input()
    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $user_input = GUIGetMsg()
        Select
            Case $user_input > 0
                MsgBox(0, $user_input, $user_input)
                ExitLoop
        EndSelect
    WEnd
EndFunc

Also When I click ok on the window that says 3 the window closes and the script terminates. Any idea why?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

OK I got it to output the message but it doesn't read the input in its entirety. For instance I type in 123 and the msgbox states just the 3. Heres the working code.

Func Get_user_input()
    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $user_input = GUIGetMsg()
        Select
            Case $user_input > 0
                MsgBox(0, $user_input, $user_input)
                ExitLoop
        EndSelect
    WEnd
EndFunc

Also When I click ok on the window that says 3 the window closes and the script terminates. Any idea why?

Did you even look at my previous reply????

The reason you only see "3" as your output is because that is the Gui Control ID of the $edit_field control.

You could type the word "test" in the input box and you would still only get "3" returned using the method you are.

You have to use GUICtrlRead($edit_field) to capture the data; just like in my example...

Other than that, if you compare your "working" code to my example, it should become fairly obvious why your script closes (HINT: What's your next line of code after "MsgBox(0, $user_input, $user_input)" ?)

Link to comment
Share on other sites

You're right. I didn't get back to the post before there were 2 posts and I just tried to implement the last post and it through me for a loop. I added the code to the script and the script stopped working all together. The code you gave me worked great. Thanks.

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

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