Page 1 of 1

If receives x, goto :x?

Posted: 08 Jul 2010 01:10
by Draginz
Is there a command like this? Where if, the batch requests some text, and if it matches the text it requested, then it proceeds?

Re: If receives x, goto :x?

Posted: 08 Jul 2010 11:02
by aGerman
Seems you have to learn the basics.
Have a lokk to the Command Index.

Of course, there is a way to compare an user input.

Code: Select all

@echo off &setlocal
set /p "input=Enter a or b: "
if /i "%input%"=="a" goto a
if /i "%input%"=="b" goto b
goto c

:a
echo you entered an "a"
goto :end

:b
echo you entered an "b"
goto :end

:c
echo you entered neither "a" nor "b""

:end
echo.
pause


Or not that "Spaghetti-Code-Like"

Code: Select all

@echo off &setlocal
set /p "input=Enter a or b: "
if /i "%input%"=="a" (call :a) else (
  if /i "%input%"=="b" (call :b) else call :c
)
echo.
pause
goto :eof

:a
echo you entered an "a"
goto :eof

:b
echo you entered an "b"
goto :eof

:c
echo you entered neither "a" nor "b""
goto :eof



Regards
aGerman

Re: If receives x, goto :x?

Posted: 08 Jul 2010 14:15
by Draginz
Thank you for that command index link, it's very helpful. I was looking for something like that on the site.
But can I have it so that the input has more than one letter in it? That's what I was looking for.

Re: If receives x, goto :x?

Posted: 08 Jul 2010 14:30
by aGerman
It's exactly the same.

Just pay attention that a label will be valid until the first space.
:abc 1 is the same like :abc 2.

Regards
aGerman

Re: If receives x, goto :x?

Posted: 08 Jul 2010 14:49
by Draginz
Ah, okay, thank you very much, that's very helpful!

Re: If receives x, goto :x?

Posted: 08 Jul 2010 14:59
by Draginz
Oh yeah, and one more thing:
Can I hide the 'enter a or b' text?
Edit:
Nevermind, I found out how!