Solved Can someone please check my error on this batch file?

October 31, 2016 at 18:51:48
Specs: Windows 64
@echo off
REN Batch Lab 1
SET RATING=Hello, %1.
CHOICE /C:GB "How are you today(G=Good, B=Bad)"
IF errorlevel 2 goto SORRY
ECHO That's nice.
GOTO NEXT
SORRY
ECHO Awww. I'm sorry to hear you're having a bad day.
CHOOSE /C:123 What would make you feel better (1=Go to a movie, 2=Go to sleep, 3=Play World of Warcraft)
IF errorlevel 1 goto WoW
IF errorlevel 2 goto HOME
MOVIE
x=1-Comedy
y=2-Adventure
z=3-SciFi
ECHO The three genres available are
FOR a%% IN (%x% %y% %z%) echo %%A
CHOICE /C:123 /T:10,3 Which of the above movie genres would you like to see
IF errorlevel 1 GOTO SCIFI
IF errorlevel 2 GOTO ADVEN
IF errorlevel 3 GOTO COMEDY
SCIFI
ECHO Enjoy your z movie.
CALL SURVEY z 1
GOTO NEXT
ADVEN
ECHO Enjoy your y movie.
CALL SURVEY y 1
GOTO NEXT
COMEDY
ECHO Enjoy your % movie.
CALL SURVEY x 1
GOTO NEXT
HOME
ECHO Class dismissed, go home.
ECHO NOT!
GOTO NEXT
WoW
ECHO Yeah, me too.
NEXT
IF NOT "%RATING%"="" ECHO The movie was a %%RATING.
ECHO Have a nice day, %1

See More: Can someone please check my error on this batch file?

Reply ↓  Report •


#1
October 31, 2016 at 23:36:51
Without reading the whole thing...

SORRY

is not a label

but this IS

:SORRY

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#2
November 1, 2016 at 04:47:38
✔ Best Answer
There isn't just one error in this script, more like 20.

I suggest you go read up on some batch syntax, and how to actually use the commands you're trying to use. (btw there is no command called CHOOSE)

Syntax: http://ss64.com/nt/syntax.html
Choice: http://ss64.com/nt/choice.html
For: http://ss64.com/nt/for.html
Goto: http://ss64.com/nt/goto.html (Covering labels as well)

In general, the ss64 page is a great place to figure out how commands work.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)


Reply ↓  Report •

#3
November 14, 2016 at 05:30:33
@echo off
:: %1 is the first variable in the commandline
::example test.bat testing12
::%1 will be testing12
:: in your case its probably a name
SET RATING=Hello, %1.
::variables have %'s around them, external variables [args] only have a single % infront of them.
::try typing a command in cmd.exe with /? behind it.
::example CHOICE /?
echo %RATING%
CHOICE /C gb /M "How are you today(G=Good, B=Bad)" /N
IF %errorlevel% equ 1 ECHO That's nice.&goto GOOD
IF %errorlevel% equ 2 goto BAD
::labels got a : infront of them
:BAD
::CLS clears the screen
CLS
ECHO Awww. I'm sorry to hear you're having a bad day.
CHOICE /C 123 /M "What would make you feel better (1=Go to a movie, 2=Go to sleep 3=Go to World of WarCraft)" /N
IF %errorlevel% equ 1 goto MOVIE
IF %errorlevel% equ 2 goto HOME
IF %errorlevel% equ 2 goto WoW
:MOVIE
CLS
set x=Comedy
set y=Adventure
set z=SciFi
ECHO [1] %x%
ECHO [2] %y%
ECHO [3] %z%
CHOICE /C 123 /M "Which of the above movie genres would you like to see." /N
IF %errorlevel% equ 1 GOTO SCIFI
IF %errorlevel% equ 2 GOTO ADVEN
IF %errorlevel% equ 3 GOTO COMEDY
:SCIFI
CLS
ECHO Enjoy your z movie.
PAUSE>NUL
:: >NUL will suppress the output
CALL SURVEY %z%
:: call will call a batchlabel or .bat file in %PATH%, or %CD%
:: try typing echo %PATH% or echo %CD% in CMD.exe
:ADVEN
CLS
ECHO Enjoy your y movie.
PAUSE>NUL
CALL SURVEY %y%
:COMEDY
CLS
ECHO Enjoy your %z% movie.
PAUSE>NUL
CALL SURVEY %x%
:HOME
CLS
ECHO Class dismissed, go home.
PAUSE>NUL
ECHO NOT!
PAUSE>NUL
:: will jump to :WoW, which is probably not your intention
:WoW
CLS
ECHO Yeah, me too.
PAUSE>NUL
IF NOT '%RATING%'=='' ECHO The movie was a %RATING%.
ECHO Have a nice day, %1
PAUSE>NUL

message edited by hidde663


Reply ↓  Report •
Related Solutions


Ask Question