Jump to content
Sign in to follow this  
xuzo

How to assign user input to variable with Koda

Recommended Posts

Playing with Koda and GUI today , first time ever.

Trying to understand the very, very, very basic, like:

1. Someone enters their name in input field

2. Pop up their name in message box

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
Local $Form1 = GUICreate("Form1", 466, 202, 192, 114)
Local $Name = GUICtrlCreateLabel("Name", 120, 120, 36, 17)
Local $NamePlease = GUICtrlCreateInput("NamePlease", 176, 120, 121, 21)
Local $Submit = GUICtrlCreateButton("Submit", 328, 120, 75, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $NamePlease
   MsgBox(64, "Your name is", $NamePlease)
EndSwitch
WEnd

If possible please just correct this very basic code example without complicated variables...will just confuse me! ;)

Edited by xuzo

Share this post


Link to post
Share on other sites

You need to use the function GuiCtrlRead() to get the content of controls. The variables such as $NamePlease contain only the ID of the control which is why you were seeing the number 4 in the message box rather than the entered name. I've corrected your script and added a line to display the message if the user clicks on the submit button

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
Local $Form1 = GUICreate("Form1", 466, 202, 192, 114)
Local $Name = GUICtrlCreateLabel("Name", 120, 120, 36, 17)
Local $NamePlease = GUICtrlCreateInput("NamePlease", 176, 120, 121, 21)
Local $Submit = GUICtrlCreateButton("Submit", 328, 120, 75, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_CLOSE
             Exit
        Case $NamePlease
             MsgBox(64, "Your name is", GuiCtrlRead($NamePlease))
        Case $Submit
             MsgBox(64, "Your name is", GuiCtrlRead($NamePlease))
    EndSwitch
WEnd

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...