Hello.
I'm writing a batch script for some coworkers and myself to more easily open files and programs. Would also like to use a more customized script at home.
I've pulled a sample script off the web allowing a list to be created with echo and using a "set /p" command to select items from the list to call on a function to be executed.
I'm trying to make it more user friendly but when an incorrect input like XYZ that doesn't match any of the function labels is entered the prompt will quickly display that it couldn't find the specified label. I want the prompt to stop there and to loop back to the beginning of the script.
I've tried puttin a GOTO command below the IF statement. I've tried an ELSE statement which seems to just ignore the first part of the IF statement and executes the ELSE part no matter what input was entered. Do I need another IF statement with an ERRORLEVEL check? I'm not sure how to do that, or what number is even returned when that error occurs.
Here's some sample code that highlights the issue.
Thanks. If you need anymore info let me know.
I'm writing a batch script for some coworkers and myself to more easily open files and programs. Would also like to use a more customized script at home.
I've pulled a sample script off the web allowing a list to be created with echo and using a "set /p" command to select items from the list to call on a function to be executed.
I'm trying to make it more user friendly but when an incorrect input like XYZ that doesn't match any of the function labels is entered the prompt will quickly display that it couldn't find the specified label. I want the prompt to stop there and to loop back to the beginning of the script.
I've tried puttin a GOTO command below the IF statement. I've tried an ELSE statement which seems to just ignore the first part of the IF statement and executes the ELSE part no matter what input was entered. Do I need another IF statement with an ERRORLEVEL check? I'm not sure how to do that, or what number is even returned when that error occurs.
Here's some sample code that highlights the issue.
@echo off
:start
echo choose 1
echo choose 2 to test wrong input
SET /p x=Choose an Option:
IF '%x%' == '%x%' GOTO Item_%x%
:Item_1
echo option 1 was selected
GOTO start
:Success
echo wrong input works
pause
GOTO start
Thanks. If you need anymore info let me know.