I hope everybody is OK and keeping SAFE!
I have a batch script that works well, except, if I DON'T enter a number and press <ENTER>, it exits the script. Here is the bit of code that I think is affecting it . . .
Code: Select all
setlocal EnableDelayedExpansion
set "userinput="
set /p "userinput=>Enter a Menu number and press <Enter>: "
if /i %userinput%==0 goto Exit_Program
if /i %userinput%==1 goto Standard
if /i %userinput%==2 goto Advanced
In fact, it is only the set /p that is giving me a problem!
I have a couple of scripts in the same format except they use Choice instead, and when I press <ENTER> instead of entering a number it does NOT close the batch file but waits for a valid number input.
I have tried . . .
Code: Select all
if /i '%userinput%'=='0' goto Exit_Program
if /i '%userinput%'=='2' goto Standard
if /i '%userinput%'=='3' goto Standard
Thanks in advance.
EDIT 1:
Thanks to Google, I have found a solution, although I don't know quite why it works . . .
Code: Select all
if /i [%userinput%]==[] cls & goto :Menu
Thanks in advance.
EDIT 2:
OK, this works sort of!
Code: Select all
if /i "%userinput%"=="" cls & goto :Menu
if /i "%userinput%"=="0" goto Exit_Program
if /i "%userinput%"=="1" goto Standard
if /i "%userinput%"=="2" goto Advanced
if /i "%userinput%"=="R" goto Reports_Menu
There is one letter than is included in the menu [ see above ], the letter "R", which when I enter it and press <ENTER> takes me to the correct place.
Has anyone got any ideas please?
Thanks in advance.