Author Options:

Is it just me or this doesn't work..batch? Answered

 I tried making a batch and it looks something like this (it is a subsystem)Bold words need paying attention to:
echo choose your selection:
echo 1 apps
echo 2 editor
echo 3 phun not done
echo 4 sites not done
set /p choice=
if %choice%==1 goto :apps
if %choice%==2 goto editor
if %choice%==3
if %choice%==4
echo error wrong choice
goto mainmenu

I would like to KNOW the goto and heading does not work! Please tell, I need it for my subsystem and you will recieve credit for it when I post the 'ible
UPDATE Does 3 and 4 have to be filled in?


I think 3 and 4 do need to be filled in. Perhaps try:

if %choice%==3 goto mainmenu
if %choice%==4 goto mainmenu


if %choice%==1 goto apps

instead of:

if %choice%==1 goto :apps

although it shouldn't really matter.

This isn't finished - no :apps or :editor - what exactly are you asking about?


I know it is does not work in this form, It's pulled from a 408- lined batch document you don't expect me to paste it do you?, leave that I was asking why won't the batch document goto the top when you enter a wrong number in the set /p choice bit

You're missing a colon? Or is that a typing error on this page?


and the first goto :apps, then goto editor - no colon.  Have to keep the syntax straight.

Yes I noticed that, but as g-one also observes it's a job half-done.



8 years ago

set choice=
you can't enter something
set /p choice=

if %choice%==3
if %choice%==4

your batch will crash because a command is expected, e.g.
if %choice%==3 echo 3 was entered
if %choice%==4 echo 4 was entered

I did this wrong you seem to be right but it was meant to be set /p chioce, I couldn't paste words for some reason so I had to retype it and made errors, Ill change it