1.

Solve : Help...?

Answer»

I have a CODE...


@echo off
echo.
echo. Please Select the TASK you want to execute.
echo.
echo 1-Install SOFTWARES
echo 2-Install GAMES
echo 3-Play a game
echo.
set /p T= Select 1,2 or 3 and then press Enter:
echo.
If %T%==1 GOTO softwaremenu
IF %T%==2 GOTO gamesmenu
If %T%==3 GOTO playgame


Now if d USER types anything other than 1,2 or 3 the batch ends...
I want it to flash back a msg sayin to check no. entered & enter again....

Plz...help me...Try this.


Code: [Select]@echo off
:beginning
echo.
echo. Please Select the task you want to execute.
echo.
echo 1-Install SOFTWARES
echo 2-Install GAMES
echo 3-Play a game
echo.
set /p T= Select 1,2 or 3 and then press Enter:
echo.
If %T%==1 GOTO softwaremenu
IF %T%==2 GOTO gamesmenu
If %T%==3 GOTO playgame
cls
code here
pause
cls
goto :beginningAnd what about if they just press Enter?
Quote from: Salmon Trout on August 17, 2009, 05:56:35 AM

And what about if they just press Enter?

If its not 1, 2 or 3 then it loops.Quote from: Helpmeh on August 17, 2009, 05:58:24 AM
If its not 1, 2 or 3 then it loops.

In the IF test, since %T% is (hopefully) a string, if you don't have any "quotes" or .dots. or {spider brackets} etc around the input variable %T% and the comparison value then it will crash if just Enter is PRESSED. Enter is an empty string.

So, if just Enter is pressed -

If %T%==1 GOTO softwaremenu

expands

to

If ==1 GOTO softwaremenu

This will cause an error.

So do it like this

If "%T%"=="1" GOTO softwaremenu

Then if enter is pressed it expands to this

If ""=="1" GOTO softwaremenu



Ahh. Makes sense.


Discussion

No Comment Found