TheCrimsonCrusader Posted April 9, 2008 Share Posted April 9, 2008 This is a basic script that when you click on the button, it brings up an input box with an "OK" and "Cancel" button. When inputting text in the input field and clicking on the "OK" button the rest of the function behaves correctly, which basically writes to a text file in the root of C:\ and then brings up a message box saying what the input was.. However, when I click on the "Cancel" button, it still processes the rest of the function for the next "if" statement. What I would like it to do is when you click on the "Cancel" button, it just returns to the original GUI. I'm thinking it is a one line type mistake with the "EndIf' statement after the file write request being the problem, but I haven't been able to work around that. Any help would be greatly appreciated! CODE#include <GuiConstants.au3> Opt("TrayIconHide", 1) Opt ("GUIOnEventMode", 1) WinSetOnTop("Title Bar", "", 1) GUICreate("Title Bar", 240, 60, (@DesktopWidth - 300) / 2, (@DesktopHeight - 300) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS, $WS_EX_TOPMOST) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $BUTTON = GUICtrlCreateButton("Button", 20, 30, 200, 20) GUICtrlSetOnEvent($BUTTON, "Button") GUISetState() While 1 Sleep(1000) WEnd Func Button() $text = InputBox("Title Bar of Input Box", "Please enter some text and then click OK.") If @error = 1 Then ;want return to GUI here instead of it processing the next "if" statement within the function. Else FileWriteLine("c:\test.txt",$text) EndIf If $text = $text then MsgBox(0,"Title Bar of Message Box",$text) EndIf EndFunc ;==>Button Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE EndSelect EndFunc ;==>SpecialEvents Link to comment Share on other sites More sharing options...
jlorenz1 Posted April 9, 2008 Share Posted April 9, 2008 (edited) Hi, you have chossen the wrong forum. Please post with it in the GUI forum. Edited April 9, 2008 by jlorenz1 Johannes LorenzBensheim, Germanyjlorenz1@web.de[post="12602"]Highlightning AutoIt Syntax in Notepad++ - Just copy in your Profile/application data/notepad++[/post] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 9, 2008 Moderators Share Posted April 9, 2008 Func Button() Local $text = InputBox("Title Bar of Input Box", "Please enter some text and then click OK.") If @error = 1 Then Return Return FileWriteLine(@HomeDrive & "\test.txt", $text) EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 9, 2008 Moderators Share Posted April 9, 2008 Hi,you have chossen the wrong forum. Please post with it in the GUI forum.Although he may have had a GUI, his question wasn't GUI specific. It is more of a lack of understanding on how to escape a function after an error. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
YellowLab Posted April 9, 2008 Share Posted April 9, 2008 Are you deleting the file between test runs? The only difference between clicking Okay and Cancel is the file will be written; however, if the file already exists it won't change as the line will continually be overwritten. The message box will display if either button is clicked. Also, curious about this statement: If $text = $text then Seems unnecessary to me, won't $text always equal $text? Bob You can't see a rainbow without first experiencing the rain. Link to comment Share on other sites More sharing options...
GEOSoft Posted April 9, 2008 Share Posted April 9, 2008 First off you say Message Box when it appears it is the Input that you really wanted to refer to. $text = InputBox("Title Bar of Input Box", "Please enter some text and then click OK.") If @error = 1 Then Return George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
TheCrimsonCrusader Posted April 9, 2008 Author Share Posted April 9, 2008 Much apprecation Smoke! That's the logic I was looking for. And as far as the $test=$test, I should stay off the drugs and pay more attention. J/K on the 1st part. I tried return previously, but I had it on a separate line, whcih wasn't processing correctly. I wasn't so much concerned with what the overall process was doing, but how to get it returned to the initial GUI without processing the function when clicking on the "Cancel" button. Thanks to all! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now