| View previous topic :: View next topic |
| Author |
Message |
4birds
Joined: 06 Mar 2008 Posts: 167
|
Posted: Mon Mar 17, 2008 5:43 am Post subject: Help canceling a input box |
|
|
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 |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
Posted: Mon Mar 17, 2008 6:50 am Post subject: |
|
|
| See the help file for InputBox it gives the example you need. |
|
| Back to top |
|
 |
4birds
Joined: 06 Mar 2008 Posts: 167
|
Posted: Mon Mar 17, 2008 12:43 pm Post subject: |
|
|
| 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 |
|
 |
Firewolf91
Joined: 19 Oct 2007 Posts: 134 Location: PA
|
Posted: Mon Mar 17, 2008 1:58 pm Post subject: |
|
|
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 |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
|
| Back to top |
|
 |
Firewolf91
Joined: 19 Oct 2007 Posts: 134 Location: PA
|
Posted: Mon Mar 17, 2008 3:32 pm Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
|