Solved problem with Batch inputs

February 15, 2013 at 15:12:55
Specs: Windows 8
Hello I have been trying to create a batch program. The program i am making is a file organizing system that uses file extensions to find files. I have pretty much everything set up but I can not get it to work with wrong inputs. I need a code for if someone types a wrong code i need to send them to a :Wrong code group.

See More: problem with Batch inputs

Report •

✔ Best Answer
February 15, 2013 at 21:33:30
Mike's suggestion is right on target, then.
:: always "clear" a var. prior to "set /p"!
:loopback
set number=
set /p number=
if /i %number% == school goto open
if /i %number% == batch goto open1
if /i %number%==xxx goto open2
if ... goto
if ... goto
:: all others have "gone to" their destinations, nothing but error left...
goto :wrong
...
:wrong
echo invalid entry.
goto :loopback


#1
February 15, 2013 at 18:58:27
Depending on how it's set up. Note that there is no example script above. I would just add a toto after the input script, that way if everything fails it loops.

Example
:beginning

::Bunch of test lines here
If one equ two goto next
...
Goto fails

:fails
Echo I'm sorry that combination isn't available
Goto beginning

:: mike


Report •

#2
February 15, 2013 at 19:00:08
It would probably help if you posted your code, since everyone's approach is different. Here's my take on it:
@echo off & setlocal
:10
set wr=wrong
set x=
set /p x=label:
if not defined x goto :eof
call :%x% 2>nul
goto :%wr%
:1
echo ok 1
goto :exx
:2
echo ok two
goto :exx
:wrong
echo WRONg?????
GOTO :10
:exx
set wr=10
::===== end snippet
If all the extensions use the same code, you can stack them, like:
:exe
:bat
:wmf
:pdf
echo processing %0
blah blah blah

This should have worked but didn't (hint: anyone out there know why?):
call :label 2>nul || goto :WrongAnswerDude
my errorlevel was always 1 regardless, so it always executed Wrong. Even as a code-block (call :label), it still threw an errorlevel.

oops, hi Mike, crossed in the mail!


Report •

#3
February 15, 2013 at 19:18:32
Oh sorry for not adding example code I am using basic batch codes this is how i am setting it up

this is how i am setting it up
set /p number=

if %number% == school goto open
if %number% == batch goto open1


:wrong

if i could get a code to use if the entered text does not match any inputs i have set
like a goto wrong


Report •

Related Solutions

#4
February 15, 2013 at 21:33:30
✔ Best Answer
Mike's suggestion is right on target, then.
:: always "clear" a var. prior to "set /p"!
:loopback
set number=
set /p number=
if /i %number% == school goto open
if /i %number% == batch goto open1
if /i %number%==xxx goto open2
if ... goto
if ... goto
:: all others have "gone to" their destinations, nothing but error left...
goto :wrong
...
:wrong
echo invalid entry.
goto :loopback

Report •

Ask Question