Problem With Menu

February 24, 2010 at 20:02:50
Specs: Windows Vista
Im basicly new to this and was doing good. i created a simple menu and it worked fine, then i tried to put a shutdown function in and i dont really know what i changed to cause this but it now closes right when i open it. i thought maybe someone could spot what i did and help thanks

@echo off
title Basic Menu
color 0a
:menu
cls
echo.
echo 1-Calculator
echo.
echo 2-Firefox
echo.
echo 3-Notepad
echo.
echo 4-Cmd prompt
echo.
echo 5-Aim
echo.
echo 6-Shutdown
echo.
set input=
set /p input==Enter choice here:
if %input%==1 goto 1
if %input%==2 goto 2
if %input%==3 goto 3
if %input%==4 goto 4
if %input%==5 goto 5
if %input%==lkeball85 goto edit
if %input%==6 goto 6
goto menu
:1
start calc
cls
echo You choose Calculator
pause
cls
goto menu
:2
"C:\Program Files\Mozilla Firefox\firefox.exe"
cls
echo You choose Firefox
pause
goto menu
:3
%SystemRoot%\system32\notepad.exe
cls
echo You choose notepad
pause
goto menu
:4
start cmd
cls
echo You choose Command prompt
pause
goto menu
:5
"C:\Program Files\AIM6\aim6.exe" /d locale=en-US ee://aol/imApp
cls
echo You choose Aim
pause
goto menu
:edit
"C:\Users\Nicholas\Desktop\Batch Files\menu.txt"
cls
echo You choose Edit Option
pause
goto menu
:6
set input=
set /p input=Are you sure you want to shtudown? (yes/no)
if %input%==yes goto yes
if %input%==no goto no
if %input%==Yes goto yes
if %input%==YES goto yes
if %input%==No goto no
if %input%==NO goto no
goto menu
:yes
shutdown -s -t 180 -c "shutdown in 3 minutes"
cls
echo You choose yes
goto abort
:no
goto menu
cls
echo You choose no
goto menu
set input=
set /p input=Do want to abort shutdown? (y/n)
if %input%==y goto y
if %input%==Y goto y
if %input%==n goto n
if %input%==N goto n
goto menu
:y
shutdown -a
cls
echo Shutdown abborted
got menu
:n
msgbox Shutdown will continue


See More: Problem With Menu

Report •


#1
February 24, 2010 at 21:35:15
fix this line:
set /p input==Enter choice here:

one too many equalses:

set /p input=Enter choice here:

otherwise no prob. except now MY SCREEN IS GREEN!!!
(just joking, Lol)


Report •

#2
February 25, 2010 at 03:48:06
if %input%==yes goto yes
if %input%==no goto no
if %input%==Yes goto yes
if %input%==YES goto yes
if %input%==No goto no
if %input%==NO goto no

replace into

if /i %input%==YES goto yes
if /i %input%==No goto no

If you would use the first mentioned code, you need to capture YEs as well, and yEs, and ... etc


Report •

#3
February 25, 2010 at 03:56:32
LOL

You can avoid all this clutter:

set /p input==Enter choice here:
if %input%==1 goto 1
if %input%==2 goto 2
if %input%==3 goto 3
if %input%==4 goto 4
if %input%==5 goto 5
----------------------

goto :%input%


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
February 25, 2010 at 03:57:00
Nick, when I run it, it just says :

The syntax of the command is incorrect.
goto was unexpected at this time.

So, you would see the same if you launch it in a DOS box (NOT by clicking it in Explorer, since then it will go away in less than a second). Obviously, there's an error in it:

This is what you get when you replace ECHO OFF with ECHO ON:

D:\Temp>set /p input==Enter choice here:
The syntax of the command is incorrect.
goto was unexpected at this time.

D:\Temp>if ==1 goto 1


So, here's some advice (apart from the syntax error in SET where you have double =)

1. Never use IF with = and only specify a variable on either side of the = ... if the var. is empty, you have syntax error, which you cannot catch in a programmatical way.

2. Check your labels, I see a call to "abort", but the label does not exist ?!

3. Don't use labels that say nothing, like "yes" or "no"
Yes, what ?
No, what ?


Report •

#5
February 25, 2010 at 04:16:50
I also like the MSGBOX command ... I'm too lazy today to even put it in Google. Can somebody tell me a story on this one ? Is it MS ? Open source ? Need to write it myself ?

Report •

#6
February 25, 2010 at 05:53:47
Thanks all of you guys. Ill try out all of your suggestions and check everything over again. Thanks for the tip with echo on.

Report •

#7
February 25, 2010 at 05:59:31
I tried everything and getting rid of the double equal signs worked. Ill probably get rid of the cluttered yes no code. If anyone wants to use this code go for it and try to make it better i really dont care. thanks again for all your great responses. Ill remember to come here for anything elses. Thanks

Report •

#8
February 25, 2010 at 06:06:04
Oh and right when i wrote this post i realized MSGBOX might not be a real command and that i did not follow up on the abort.
thanks again
-Nick

Report •

#9
February 25, 2010 at 07:56:08
One more question, how can i make it so that if a user enters and incorrect or no nummber it will display that that is not a choice and go back to the menu. I played around with it but i cant firure it out.



Report •

#10
February 26, 2010 at 08:55:13
I've just taken the code of the opening post, and adapted to display one way of solving that:

(..)
echo.
:question
set input=
set /p input==Enter choice here:
if %input%==1 goto 1
if %input%==2 goto 2
if %input%==3 goto 3
if %input%==4 goto 4
if %input%==5 goto 5
if %input%==lkeball85 goto edit
if %input%==6 goto 6
echo.
echo This is not a valid choice (%input%)
echo.
goto question
(..)

Be aware this is the initial code of opening post, without all other changes needed, mentioned in response 1 until previous one.


Report •

#11
February 26, 2010 at 12:50:02
Thanks for the help in the last post my menu is really coming together although if a user just presses enter without inputting a number the batch closes and i tried it a few times and it looks like it is saying an unexpected error has occurred before closing. Does anyone know what might be happening?

Report •

#12
February 26, 2010 at 13:35:29
Well, if the below line is exactly like this, it'll syntax error out when exactly pressing enter only:

if %input%==1 goto 1


Report •

#13
February 26, 2010 at 13:59:01
I know that's whats been happening and i want it to got back to the menu and possibly say that that is an incorrect choice when just enter is pressed. thanks tho

Report •

#14
February 26, 2010 at 17:15:26
?
if "%input% equ "" goto :question

Report •

#15
February 27, 2010 at 04:28:48
Just post the current code, Nick, and we go from there

Report •

#16
February 27, 2010 at 10:23:23
here's the code. I added a lot and haven't really gotten around to putting it in order so a lot of things look out of order and some labels are not really descriptive so it be nice to just focus on shy this error happens. I also added some code for a batch calc and a guessing game i learned so things got a little messy. thanks.


@echo off
:menu
title Basic Menu
color 9f
cls
echo.
echo 1-Calculator 11-Batch Calc
echo.
echo 2-Firefox 12-Log Out
echo.
echo 3-Notepad
echo.
echo 4-Cmd prompt
echo.
echo 5-Aim
echo.
echo 6-Shutdown
echo.
echo 7-Make File
echo.
echo 8-Icy Tower
echo.
echo 9-Guess Game
echo.
echo 10-Credits To exit, press (e) then enter.
echo.
echo ********************************************************************************
echo.
set input=
set /p input=Enter choice here:
if %input%==1 goto 1
if %input%==2 goto 2
if %input%==3 goto 3
if %input%==4 goto 4
if %input%==5 goto 5
if %input%==6 goto 6
if %input%==7 goto 7
if %input%==8 goto 8
if %input%==9 goto 9
if %input%==10 goto 10
if %input%==11 goto 11
if %input%==12 goto 12
if %input%==e goto exit
goto menu
:1
start calc
cls
echo You choose Calculator
pause
cls
goto menu
:2
"C:\Program Files\Mozilla Firefox\firefox.exe"
cls
echo You choose Firefox
pause
goto menu
:3
"C:\Users\Nicholas\Desktop\Batch Files\npp.5.6.7.bin\unicode\notepad++.exe"
cls
echo You choose notepad
pause
goto menu
:4
start
cls
echo You choose Command prompt
pause
goto menu
:5
"C:\Program Files\AIM6\aim6.exe" /d locale=en-US ee://aol/imApp
cls
echo You choose Aim
pause
goto menu
:6
title Shutdown
cls
set input=
set /p input=Are you sure you want to shtudown? (yes/no)
if %input%==yes goto yes
if %input%==no goto no
goto 6
:yes
shutdown -s -t 180 -c "Shutdown in 3 minutes"
cls
echo You choose yes
goto abort
:no
goto menu
cls
echo You choose no
goto menu
:abort
set input=
set /p input=Do you want to abort shutdown? (y/n)
if %input%==y goto y
if %input%==n goto n
goto abort
:y
shutdown -a
cls
echo Shutdown abborted
pause
goto menu
:n
cls
echo Thanks for using Nicks menu!
pause
exit
:7
@echo off
:start
cls
echo You choose new folder
pause
cls
color 97
title Folder Maker
:top3
cls
echo.
set /p _folder=Folder Name:
cd %userprofile%/Desktop
if exist "%_folder%" goto error
md "%_folder%"
echo.
echo The folder "%_folder%" has been created on your desktop.
echo.
pause
goto make1
:error
cls
echo.
echo The folder "%_folder%" already exists!
echo.
pause
goto top3
:make1
cls
set input=
set /p input=Do you want to make another? (yes/no)
if %input%==yes goto make
if %input%==no goto menu
goto make1
:make
cls
echo You choose to make another
pause
goto top3
:8
C:\games\icytower1.4\icytower14.exe
cls
echo You choose Icy Tower
pause
goto menu
:9
cls
@echo off
color 0e
title Guessing Game
:begin
cls
set /a guessnum=0
set /a answer=%RANDOM%
set variable1=lkeball85
echo -------------------------------------------------
echo Welcome to the Guessing Game!
echo.
echo Try and Guess my Number!
echo -------------------------------------------------
echo.
:top
echo.
set /p guess=
echo.
if %guess% GTR %answer% ECHO Lower!
if %guess% LSS %answer% ECHO Higher!
if %guess%==%answer% GOTO EQUAL
set /a guessnum=%guessnum% +1
if %guess%==%variable1% ECHO You Found the backdoor. hey?, the answer is: %answer%
goto top
:equal
echo Congratulations, You guessed right!!!
echo.
echo It took you %guessnum% guesses.
echo.
pause
:playagain
cls
set input=
set /p input=Do you want to play again, exit, or return to menu? (p/e/m)
if %input%==m goto menu
if %input%==p goto begin
if %input%==e goto exit
goto playagain
:exit
exit
:10
title Credits
cls
echo.
echo This menu and script for the Guess Game was written and created by Nick Humphreys
echo.
echo If any problems arise, send me an e-mail at nickster2013@aol.com
echo.
echo.Special thanks for the help from the people at computing.net
echo.
echo ********************************************************************************
echo.
set input=
set /p input=Do you want to go to computing.net or send me an e-mail? (c/e/both/n)
if %input%==c goto c
if %input%==e goto e
if %input%==both goto both
if %input%==n goto return
goto 10
:c
start iexplore www.computing.net
cls
echo You choose computing.net
pause
goto menu
:e
start iexplore www.aol.com
cls
echo You choose e-mail
pause
goto menu
:both
start iexplore www.aol.com
start iexplore www.computing.net
cls
echo You choose both
pause
goto menu
:return
cls
echo You choose to go back to the menu
pause
goto menu
:11
cls
@echo off
title Batch Calculator
:top2
cls
color 1f
echo --------------------------------------------------------------
echo Welcome to Batch Calculator
echo --------------------------------------------------------------
echo.
set /p sum=
set /a ans=%sum%
echo.
echo = %ans%
echo --------------------------------------------------------------
pause
cls
echo Previous Answer: %ans%
goto do
pause
:do
set input=
set /p input=Do you want to exit, stay or go to menu? (e/s/m)
if %input%==e goto leave
if %input%==s goto s
if %input%==m goto menu
goto do
:leave
cls
echo You choose to exit
pause
goto menu
:s
cls
echo You choose to stay
pause
goto top2
:12
cls
set input=
set /p input=Are you sure you want to log off? (y/n)
if %input%==y goto logout
if %input%==n goto menu
pause
goto 12
:logout
cls
echo Thanks for using Nick's menu!
pause
exit


Report •

#17
February 28, 2010 at 03:51:32
OK, for the initial question:

(..)
echo 10-Credits To exit, press (e) then enter.
echo.
echo ********************************************************************************
echo.
set input=
:question
set /p input=Enter choice here:
if "%input%"=="" goto :question
if %input%==1 goto 1
if %input%==2 goto 2
(..)

I just added the label, and the IF command to go to that label. By means of checking it is empty, the subsequent checks will not fail (with syntax error) cause %input% will not be empty. But, it should be mentioned that it is better for every IF to apply to the same rules.


Report •

#18
February 28, 2010 at 03:56:11
If you need for us to review full code, let me know, but I had a quick look, and I see the same error repeating in the code:

(..)
set /p guess=
echo.
if %guess% GTR %answer% ECHO Lower!
if %guess% LSS %answer% ECHO Higher!
if %guess%==%answer% GOTO EQUAL
(..)

If you just press the ENTER key, this will also syntax error out ... And I'm assuming you had error handling on %answer% as well.


Report •


Ask Question