Jump to content

Noob Question - GUI to variable


DoctorSLO
 Share

Recommended Posts

Hi

I'm beginner in autoit.

Here is my example script:

#include <GUIConstantsEx.au3>

GUICreate("Hello World", 500, 100)
$Input = GUICtrlCreateInput("input here", 10, 10)
$Button = GUICtrlCreateButton("OK", 250, 10)
GUISetState(@SW_SHOW)

Local $Sleep

While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $Button
        $Input = $Sleep //this is not correct
    EndSelect
WEnd

Sleep($Sleep)
//And more code following ....

Now I know this is wrong, I'm asking you how to do it correct. I want that the number I entered in Input set the $Sleep variable. I do this like this $Input = $Sleep, but something is missing, plz help ... thx

And I also need that GUI interface close when Sleep variable is set.

Edited by DoctorSLO
Link to comment
Share on other sites

Welcome to the forum! :)

Use a GuiCtrlRead function to get a data of the control.

#include <GUIConstantsEx.au3>

GUICreate("Hello World", 500, 100)
$Input = GUICtrlCreateInput("input here", 10, 10)
$Button = GUICtrlCreateButton("OK", 250, 10)
GUISetState(@SW_SHOW)

Local $Sleep

While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $Button
        $Sleep = GUICtrlRead($Input)
        MsgBox(0, "Sleep", $Sleep)
    EndSelect
WEnd
Link to comment
Share on other sites

Thank you, I do it. I just want to know how to close GUI when I press OK button on msgbox that appeared. I put $GUI_EVENT_CLOSE but its not work :)

And also the MsgBox(0, "Title", "here we go") its not show up :lmao: . I must put it in while or function ?

#include <GUIConstantsEx.au3>

GUICreate("Hello World", 500, 100)
$Input = GUICtrlCreateInput("input here", 10, 10)
$Button = GUICtrlCreateButton("OK", 250, 10)
GUISetState(@SW_SHOW)

Local $Sleep

While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $Button
        $Sleep = GUICtrlRead($Input)
        MsgBox(0, "ok", "Sleep time is " & $Sleep)
    EndSelect
WEnd

Sleep($Sleep)
MsgBox(0, "Title", "here we go")
Link to comment
Share on other sites

  • Developers

You need to exit the While-Wend loop by putting an ExitLoop function inside your Case $msg = $Button..

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thx, now its working fine. To close GUI Window I used GUISetState(@SW_HIDE). So now looks like this :

#include <GUIConstantsEx.au3>

GUICreate("Hello World", 500, 100)
$Input = GUICtrlCreateInput("input here", 10, 10)
$Button = GUICtrlCreateButton("OK", 250, 10)
GUISetState(@SW_SHOW)

Local $Sleep

While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $Button
        GUISetState(@SW_HIDE)
        $Sleep = GUICtrlRead($Input)
        MsgBox(0, "ok", "Sleep time is " & $Sleep)
        ExitLoop
    EndSelect
WEnd


Sleep($Sleep)
MsgBox(0, "Title", "here we go")

Thx

Edited by DoctorSLO
Link to comment
Share on other sites

  • Developers

Normally you would delete the GUI unless you want to display it again at a later stage or still need to read the content of any of the Controls:

$Sleep = GUICtrlRead($Input)
        MsgBox(0, "ok", "Sleep time is " & $Sleep)
        GUIDelete()
        ExitLoop

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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