VOGONS

Common searches


First post, by dosquest

User metadata
Rank Oldbie
Rank
Oldbie

Okay, I have a file needs user input (1 through 5) how do I restrict the user input. Say if someone typed "r" or another character other than 1 through 5 how would I block that input because when I input an unexpected character is crashes the program instead of ingoing it.

Reply 2 of 4, by Tetrium

User metadata
Rank l33t++
Rank
l33t++
dosquest wrote:

Okay, I have a file needs user input (1 through 5) how do I restrict the user input. Say if someone typed "r" or another character other than 1 through 5 how would I block that input because when I input an unexpected character is crashes the program instead of ingoing it.

I'm not exactly a DOS or batch guru, but I have used simple batch files extensively in the past
Can't you make a statement along the lines of

if 1 goto <your batch continues>
if 2 goto <your batch continues>
if 3 goto <your batch continues>
if 4 goto <your batch continues>
if 5 goto <your batch continues>
goto end

so that if the user input is incorrect, it simply terminates?

Whats missing in your collections?
My retro rigs (old topic)
Interesting Vogons threads (links to Vogonswiki)
Report spammers here!

Reply 3 of 4, by rfnagel

User metadata
Rank Oldbie
Rank
Oldbie

As QBix suggested, using "CHOICE.COM":

@ECHO OFF

:Top
CLS
@ECHO Your Main Menu
@ECHO --------------
@ECHO Option [1]
@ECHO Option [2]
@ECHO Option [3]
@ECHO Option [4]
@ECHO Option [5]
@ECHO.
@ECHO [Q]uit
@ECHO.
CHOICE /C:12345Q
IF ERRORLEVEL 6 GOTO Quit
IF ERRORLEVEL 5 GOTO Option5
IF ERRORLEVEL 4 GOTO Option4
IF ERRORLEVEL 3 GOTO Option3
IF ERRORLEVEL 2 GOTO Option2
IF ERRORLEVEL 1 GOTO Option1

:Option1
CLS
@ECHO This is Option 1!
@ECHO Press any key to return to the main menu...
PAUSE>NUL
GOTO Top

:Option2
CLS
@ECHO This is Option 2!
@ECHO Press any key to return to the main menu...
PAUSE>NUL
GOTO Top

:Option3
CLS
@ECHO This is Option 3!
@ECHO Press any key to return to the main menu...
PAUSE>NUL
GOTO Top

:Option4
CLS
@ECHO This is Option 4!
@ECHO Press any key to return to the main menu...
PAUSE>NUL
GOTO Top

:Option5
CLS
@ECHO This is Option 5!
@ECHO Press any key to return to the main menu...
PAUSE>NUL
GOTO Top

:Quit
CLS
@ECHO Hasta la vista, Baby!
Show last 3 lines
@ECHO Press any key to exit...
PAUSE>NUL

Rich ¥Weeds¥ Nagel
http://www.richnagel.net