Jump to content

GUICtrlRead within a MsgBox


Recommended Posts

Hey folks,

I'm just starting to learn this great program and just ran into a little snag.

I'm trying to create a window with several input areas, and where your input data will be called for in a MsgBox.

In my current attempt however I keep getting a message 'Variable used without being declared'.

I've searched around on the net (and this forum) and couldn't find a clear solution without a complete overhaul of how I'm going about it.

So in short: can I use GuiCtrlRead as part of another function? (the problem is about halfway down)

#include <GUIConstantsEx.au3> 

Opt("GUIOnEventMode", 1)  

$mainwindow = GUICreate("New tool", 440, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("Please follow the steps below ", 70, 20, 330, 20)
GUICtrlCreateGroup("Select the relevant option", 100, 65, 170, 100)
$Option1 = GUICtrlCreateButton("Option1", 130, 85, 100, 20)
$Option2 = GUICtrlCreateButton("Option2", 130, 105, 100, 20)
$Option3 = GUICtrlCreateButton("Option3", 130, 125, 100, 20)
$Close = GUICtrlCreateButton("Close", 355, 465, 70, 25)
GUICtrlSetOnEvent($Close, "Close") 
GUICtrlSetOnEvent($Option1, "Option1") 
GUICtrlSetOnEvent($Option2, "Option2") 
GUICtrlSetOnEvent($Option3, "Option3")
GUISetState(@SW_SHOW)

While 1
  Sleep(1000)  
WEnd

Func Option1()
    GUICtrlCreateLabel("Please type your input in the box below and press OK", 50, 175, 480)
    $Input1 = GUICtrlCreateInput("", 85, 195, 200, 20)
        $Ok = GUICtrlCreateButton("Ok", 285, 195, 70, 25)
        GUICtrlSetOnEvent($Ok, "Ok") 
                                    
EndFunc

Func Ok()
    MsgBox(0, "Typed text", GUICtrlRead($Input1))       
EndFunc

Func Option2()
    GUICtrlCreateLabel("Please type your input in the box below and press OK", 50, 175, 480)
    $Input2 = GUICtrlCreateInput("", 85, 195, 200, 20)
        $Ok1 = GUICtrlCreateButton("Ok", 285, 195, 70, 25)
        GUICtrlSetOnEvent($Ok1, "Ok")
EndFunc
                        
Func Option3()
    $testwindow = GUICreate("Second screen ", 200, 150) 
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") 
    GUISetState(@SW_SHOW)
            GUICtrlCreateLabel("test window, click on start", 10, 10, 190, 50)
                $Start = GUICtrlCreateButton("Start", 80, 100, 70, 25) 
                GUICtrlSetOnEvent($Start, "Start")
                
EndFunc
            
Func CLOSEClicked() 
  Exit
EndFunc

Func Close()
    Exit
EndFunc
Link to comment
Share on other sites

You can, but you have to define $input as Global if you are defining it in a function and want to read from it in another function

Like Global $input1 = Gui...

Edited by Arterie
Link to comment
Share on other sites

Thanks for the reaction Arterie, but although the problem is now clear to me I'm not sure how I can fix the problem as a whole.

If I want the user's input from the GuiCtrlCreateInput to be read by the MsgBox, how should I go about it if I want to stick to OnEventMode?

Link to comment
Share on other sites

Put Global $Input1,$Input2 at the top of the script

and change the Ok function to something like this:

Func Ok()

If $Input1 <> "" Then

MsgBox(0, "Typed text", GUICtrlRead($Input1))

Else

MsgBox(0, "Typed text", GUICtrlRead($Input2))

EndIf

EndFunc

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