AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help canceling a input box

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
4birds



Joined: 06 Mar 2008
Posts: 167

PostPosted: Mon Mar 17, 2008 5:43 am    Post subject: Help canceling a input box Reply with quote

I built an inputbox so that whatever text is entered will then be placed in another script. However, if I open the inputbox script enter nothing and decide to close it or cancel, it'll still run the notepad and send "empty" text to the pertaining script messing up the whole thing.

How do I build this thing to once cancel has been pressed or it is manually closed, it won't run the notepad and send the empty data?

Here's the code
Code:
InputBox, UserInput ,Enter,4 Digit number ie 260 = 0260,, 173,173, 616 ,101
String=%UserInput%
Clipboard:=String
Run notepad c:\acc\ClipboardScanner.ahk


thanks
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Mon Mar 17, 2008 6:50 am    Post subject: Reply with quote

See the help file for InputBox it gives the example you need.
Back to top
View user's profile Send private message
4birds



Joined: 06 Mar 2008
Posts: 167

PostPosted: Mon Mar 17, 2008 12:43 pm    Post subject: Reply with quote

nope, that didn't do the trick. Yes, it brings up the message box "you pressed cancel" but it still runs the script which will input empty data into the script.
Back to top
View user's profile Send private message
Firewolf91



Joined: 19 Oct 2007
Posts: 134
Location: PA

PostPosted: Mon Mar 17, 2008 1:58 pm    Post subject: Reply with quote

did u want to exit the script on cancel?
or just exit the input box and return to something else?

if you'd like to exit the script on cancel, then:
Code:
ButtonCancel:
ExitApp

this should work. i can't see your code, so i don't know what else you have in there. this may or may not conflict with other controls.
do you have any example code we could see?

you can also use the example in the help file (altho you said it doesn't work, but it depends what you put under the conditions (if / else)
for example:
Code:
if ErrorLevel
    MsgBox, CANCEL was pressed.
else
    MsgBox, You entered "%UserInput%"

just get rid of the MsgBox lines and add what you want.
so if you're looking to EXIT the script on cancel, then do:
Code:
InputBox, UserInput ,Enter,4 Digit number ie 260 = 0260,, 173,173, 616 ,101
if ErrorLevel
    ExitApp
else
String=%UserInput%
Clipboard:=String
Run notepad c:\acc\ClipboardScanner.ahk

ExitApp


**Code is untested**
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Mon Mar 17, 2008 3:21 pm    Post subject: Reply with quote

Also read:
http://www.autohotkey.com/docs/commands/Block.htm
http://www.autohotkey.com/docs/commands/IfEqual.htm

If you have more than one line of code that needs to be
run for if/else you must use {}
Back to top
View user's profile Send private message
Firewolf91



Joined: 19 Oct 2007
Posts: 134
Location: PA

PostPosted: Mon Mar 17, 2008 3:32 pm    Post subject: Reply with quote

what hugov said.

the code (3 lines) under the ELSE will probably need to be enclosed in { } if not used like i have above.
the reason i didn't have braces was because if cancel was pressed, it exits the script. thus the rest of the code will not be processed. if you are not exiting the script, you will want braces around the code under the else.

use it how you want, this is just an example based off the code snippet u provided us, Flight4birds.

but it is good habit to get into to enclose all code in braces under else/if's etc...don't leave them out like i did, regardless. Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group