Question about IF
Posted: 25 Mar 2011 00:12
Hi All
Please go through following bat file.
@echo off
:menu
1 Generate report staff
2 Generate report subjects
3 Generate report class
4 exit
echo.
set /p sample=Type option:
if "%sample%"=="1" call r1.bat
if "%sample%"=="2" call r2.bat
if "%sample%"=="3" call r3.bat
if "%sample%"=="4" goto Quit
if "%web%" gtr "4" goto Message
if "%web%" lss "1" goto Message
goto menu
:Message
echo you entered incorrect option
pause
goto menu
:Quit
exit
My question is that when I enter option, It perform the action correctly but when I enter nothing, perform the last action. For example when I enter 1 for option then generate the staff report. Then I enter nothing for the option it also perform last action which is generate the staff report. Please could anyone to explain for reson that. Acutually I expect to display "You entered incocorrect option" message when I enter nothing for option.
Thank You
Please go through following bat file.
@echo off
:menu
1 Generate report staff
2 Generate report subjects
3 Generate report class
4 exit
echo.
set /p sample=Type option:
if "%sample%"=="1" call r1.bat
if "%sample%"=="2" call r2.bat
if "%sample%"=="3" call r3.bat
if "%sample%"=="4" goto Quit
if "%web%" gtr "4" goto Message
if "%web%" lss "1" goto Message
goto menu
:Message
echo you entered incorrect option
pause
goto menu
:Quit
exit
My question is that when I enter option, It perform the action correctly but when I enter nothing, perform the last action. For example when I enter 1 for option then generate the staff report. Then I enter nothing for the option it also perform last action which is generate the staff report. Please could anyone to explain for reson that. Acutually I expect to display "You entered incocorrect option" message when I enter nothing for option.
Thank You