Solved Batch jumping over Choice command(? I think)

April 23, 2012 at 00:45:57
Specs: Windows 7, Intel core 2 duo 1,60 GHz/2 GB RAM
For me it seems as my program jumps over the choice commands. Although it most lightly don't, I just can't see what i did wrong. I'm probably just overlooking something, i just need some help to see what.

My current code:

if not exist "C:\Users\%username%\AppData\Random.clss" goto test1
goto menu
:test1
if not exist "C:\Documents and Settings\%username%\AppData\Random.clss" exit
:menu
echo off
color 07
if exist "C:\Users\%username%\AppData\Random.clss" set path=C:\Users\%username%\AppData
if exist "C:\Documents and Settings\%username%\AppData\Random.clss" set path=C:\Documents and Settings\%username%\AppData
cls
echo.
echo 1) Login!
echo.
echo 2) Sign Up!
echo.
echo 3) exit :(
echo.
echo Number of Choice:
choice /c 123
if %errorlevel% == 1 goto signin
if %errorlevel% == 2 goto signup
if %errorlevel% == 3 goto exit

:exit
echo.
echo Are you sure you want to exit?
choice /c yn
if %errorlevel% == 1 exit
if %errorlevel% == 2 goto menu

:signup
cls
echo Sign up
echo.
set /p newname=New Username:
set /p newpass=New Password:

::end

A pair of new eyes are much appreciated
Thanks in advance


See More: Batch jumping over Choice command(? I think)

Report •


#1
April 23, 2012 at 05:32:13
✔ Best Answer
if exist "C:\Users\%username%\AppData\Random.clss" set path=C:\Users\%username%\AppData
if exist "C:\Documents and Settings\%username%\AppData\Random.clss" set path=C:\Documents and Settings\%username%\AppData

Okay, a number of problems here.
1) You should use %AppData%, instead of trying to divine the directory yourself.
2) The default for WinXP machines for AppData is "%UserProfile%\Application Data"
3) Don't ever, ever, ever, set the %Path% variable, ever.
4) CHOICE isn't in WinXP, so you're limiting yourself to Vista+.
5) Never call EXIT from your script. It's my Command Prompt window, and I don't appreciate you taking it away from me.
6) Don't name labels after commands.

How To Ask Questions The Smart Way


Report •

#2
April 25, 2012 at 04:13:58
Thanks for the reply and thanks for the heads-up on #3 there and for #2 i had not looked up the path yet so it was guessing :P . #1, 4 i didn't know thanks :) #6 I have never had a problem with that before but i guess i just as easily could use something else, thanks. #5 i assume you refer to the "If not exist" at the start, its just a fun thing for me to have kind of a failsafe like function :P

but it still don't fix the original problem with the choice command :/
Any further help is highly appreciated! :)


Report •

#3
April 25, 2012 at 05:32:27
#5 i assume you refer to the "If not exist" at the start
That too, but namely:
if %errorlevel% == 1 exit
If you require an alternate solution, go with goto :EoF

but it still don't fix the original problem with the choice command :/
Fix what I mentioned in my last post and get back to me.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
April 25, 2012 at 23:43:56
wow thats weird i have never had a problem with using :exit before. But now it works so THANKS!

Report •

#5
April 26, 2012 at 03:23:50
(It was #3 that fixed it, not #5.)

How To Ask Questions The Smart Way


Report •


Ask Question