Jump to content
Sign in to follow this  

Exiting conditional without exiting Gui

Recommended Posts


Hello Scripters

I'm new to AutoIt, but I have a background in PHP and Javascript, and some time with VisualBasic 4.

I'm trying to exit out of a conditional without exiting the gui.

I'm testing for text in an input, if no text is found throw a message box and stop. Do not exit GUI.

If I use the Exit keyword the GUI exits completely. I do not want this to happen.

How do I do this in AutoIt?

I have searched the AutoIt Help file, and this forum, with no luck. Please help.

My Script

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)
AutoItSetOption("MustDeclareVars", 1)

;Declare variables
    Global $mainForm
    Global $menuFile, $menuFileItemExit
    Global $txtInput, $cmdAdd

;Create main window
    $mainForm = GUICreate("Add Text To File", 400, 150, (@DeskTopWidth - 400)/2, (@DeskTopHeight - 150)/2)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
;Create File menu and items
    $menuFile = GUICtrlCreateMenu("&File")
    $menuFileItemExit = GUICtrlCreateMenuItem("E&xit", $menuFile)
    GUICtrlSetOnEvent($menuFileItemExit, "CLOSEClicked")
;Create input text box
    $txtInput = GUICtrlCreateInput("",20, 40, 300, 20)
    $cmdAdd = GUICtrlCreateButton("Add", 325, 40, 40, 20)
;Create add Button
    GUICtrlSetOnEvent($cmdAdd, "AddText")
;Show GUI

while 1

;Add Text To File Func
    func AddText()
        Local $NL, $txt, $handle, $write, $close
        $NL = @CRLF;Carraige return and line feed
        $txt = GUICtrlRead($txtInput)

        If $txt = "" Then 
            MsgBox(48, "No Text", "There isn't any text to enter!")

        $handle = FileOpen("text.txt", 1)
        $write = FileWrite($handle, $txt & $NL)
        $close = FileClose($handle)
        GUICtrlSetData($txtInput, "")
        MsgBox(0, "Added Text", $txt)

;Exit GUI
    Func CLOSEClicked()

Share this post

Link to post
Share on other sites

Return quits current function:

If $txt = "" Then 
              MsgBox(48, "No Text", "There isn't any text to enter!")

Thanks. I new it was simple.

I just realized I could have used an if else statement....

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.