Computing.Net > Forums > Programming > batch menu

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch menu

Reply to Message Icon

Name: romeo_0600191
Date: October 15, 2008 at 06:06:13 Pacific
OS: vista
CPU/Ram: AMD turion X2...3gig RAM
Product: Hp
Comment:

hi
i was trying to create a batch file but im getting some unwanted results. wen it runs and i select an option the program brings up all the option and does not exit..

@ECHO OFF

echo MAIN LUNCH MENU:

echo 1.Staff
echo 2.Student
echo 3.Exit

set INPUT=
set /p INPUT=Enter choice....

If "%input%"=="1" goto staff
If "%input%"=="2" goto student
If "%input%"=="3" goto exit

:STAFF
start c:\Users\Jahildar\staffmenu.bat

:STUDENT
start c:\Users\Jahildar\studentmenu.bat

:EXIT
start c:\Users\Jahildar> exit

can somebody help me please???????



Sponsored Link
Ads by Google

Response Number 1
Name: astroraptor
Date: October 15, 2008 at 06:11:27 Pacific
Reply:

Correction (no need for EXIT):

@ECHO OFF

echo MAIN LUNCH MENU:

echo 1.Staff
echo 2.Student
echo 3.Exit

set INPUT=
set /p INPUT=Enter choice....

If "%input%"=="1" goto staff
If "%input%"=="2" goto student
If "%input%"=="3" goto :EOF

:STAFF
start c:\Users\Jahildar\staffmenu.bat
Goto :EOF

:STUDENT
start c:\Users\Jahildar\studentmenu.bat


0

Response Number 2
Name: Mechanix2Go
Date: October 15, 2008 at 07:01:54 Pacific
Reply:

No point in clearing a var and setting it on the next line.

==============================
@ECHO OFF

echo MAIN LUNCH MENU:

echo 1.Staff
echo 2.Student
echo 3.Exit

set /p INPUT=Enter choice....

goto :%INPUT%

:1
start c:\Users\Jahildar\staffmenu.bat
Goto :EOF

:2
start c:\Users\Jahildar\studentmenu.bat

:3


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: klint
Date: October 15, 2008 at 07:31:11 Pacific
Reply:

M2: "No point in clearing a var and setting it on the next line." The reason it's done is that the SET /P command does NOT set the variable if the user just presses Enter - it leaves it with its previous value. Suppose you already had a variable named input with value 2 before you run the batch file...

So I would say Jahildar was correct in initialising the variable prior to setting it with SET /P.

Some comments on the code:

1. If the user presses 4 or any other invalid value, the batch file should go back and re-print the menu. It should only proceed once the user has entered 1, 2 or 3.

2. The START commands run the other batch files in new windows. Is that what you want, or do you just want to run the other batch files in the same window?


0

Response Number 4
Name: IVO
Date: October 15, 2008 at 07:31:52 Pacific
Reply:

Fail safe version...

@ECHO OFF
:LOOP
echo MAIN LUNCH MENU:
echo 1.Staff
echo 2.Student
echo 3.Exit

set /p INPUT=Enter choice....
for %%j in (1 2 3) do if "%%j"=="%INPUT%" goto :%INPUT%
cls
goto :LOOP

:1
start c:\Users\Jahildar\staffmenu.bat
Goto :EOF

:2
start c:\Users\Jahildar\studentmenu.bat

:3


0

Response Number 5
Name: romeo_0600191
Date: October 15, 2008 at 07:56:17 Pacific
Reply:

klint...i want to run them in different windows


0

Related Posts

See More



Response Number 6
Name: romeo_0600191
Date: October 15, 2008 at 08:05:26 Pacific
Reply:

THIS is what happen after i press 1 from main menu.
- the staff menu comes up..main closes
- press one from staff:
* lunch menu comes up...staff menu stays with C:\users\jahildar> at the end

how do i get stagg menu to close as well?
here is the code:

@ECHO OFF

echo Staff LUNCH MENU:

echo 1.Show list of lunch items and cost
echo 2.Buy item
echo 3.return to Main

set INPUT=
set /p INPUT=Enter choice....

goto:%input%


:1
start c:\Users\Jahildar\item.bat
goto:EOF

:2
start c:\Users\Jahildar\buy1.bat
goto:EOF

:3
start c:\Users\Jahildar\menu.bat


0

Response Number 7
Name: klint
Date: October 15, 2008 at 08:29:46 Pacific
Reply:

You can use the EXIT command instead of GOTO :EOF, but be aware that if you then try to test the batch file by typing its name at the command prompt, it will close your command prompt window when it exits.


0

Response Number 8
Name: klint
Date: October 15, 2008 at 08:32:34 Pacific
Reply:

Ignore my previous post. Better solution below:

Instead of START batchfilename.bat

have START cmd /c batchfilename.bat


0

Response Number 9
Name: romeo_0600191
Date: October 15, 2008 at 09:08:31 Pacific
Reply:

not working


0

Response Number 10
Name: Mechanix2Go
Date: October 15, 2008 at 09:09:20 Pacific
Reply:

The solution to preventing surprise vales is to SETLOCAL.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 11
Name: klint
Date: October 15, 2008 at 09:25:09 Pacific
Reply:

(For M2):

SETLOCAL doesn't prevent global values from being visible.

To see what I mean, try the following batch file:

setlocal
set /p windir=Please just press Enter:
set windir


0

Response Number 12
Name: klint
Date: October 15, 2008 at 09:31:55 Pacific
Reply:

Combining all the suggestions from various posters above, here is a "final" version. Please try it.

@ECHO OFF
SETLOCAL
:LOOP
echo MAIN LUNCH MENU:
echo 1.Staff
echo 2.Student
echo 3.Exit

set INPUT=
set /p INPUT=Enter choice....
for %%j in (1 2 3) do if "%%j"=="%INPUT%" goto :%INPUT%
cls
goto :LOOP

:1
start cmd /c c:\Users\Jahildar\staffmenu.bat
Goto :EOF

:2
start cmd /c c:\Users\Jahildar\studentmenu.bat

:3


0

Response Number 13
Name: Mechanix2Go
Date: October 15, 2008 at 10:08:07 Pacific
Reply:

@ECHO OFF
setLocal EnableDelayedExpansion

echo MAIN LUNCH MENU:

echo 1.Staff
echo 2.Student
echo 3.Exit

set /p INPUT=Enter choice....

goto :!INPUT!

:1
start c:\Users\Jahildar\staffmenu.bat
Goto :EOF

:2
start c:\Users\Jahildar\studentmenu.bat

:3


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 14
Name: klint
Date: October 15, 2008 at 10:24:42 Pacific
Reply:

Usage scenario doesn't look very user-friendly:

C:\>MENU
MAIN LUNCH MENU:
1.Staff
2.Student
3.Exit
Enter choice....4
The system cannot find the batch label specified - 4
C:\>

That's why the loop is there.


0

Response Number 15
Name: romeo_0600191
Date: October 15, 2008 at 10:39:13 Pacific
Reply:

i got it working...THANK U GUYS FOR HELPING. Ya'll are good at these stuff. what i learn here today is basically my first tutorial class for batch files. THANK U A LOT.


0

Response Number 16
Name: Mechanix2Go
Date: October 15, 2008 at 10:59:18 Pacific
Reply:

"The system cannot find the batch label specified - 4"

If the user isn't smart enough to pick one of 3 choices offered... not much hope.

=================================
Also, not much point in STARTing another bat if the first one is going to end.

=================================
@ECHO OFF
setLocal EnableDelayedExpansion

echo MAIN LUNCH MENU:

echo 1.Staff
echo 2.Student
echo 3.Exit

set /p INPUT=Enter choice....

goto :!INPUT!

:1
c:\Users\Jahildar\staffmenu.bat

:2
c:\Users\Jahildar\studentmenu.bat

:3


=====================================
If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch menu

batch menu input www.computing.net/answers/programming/batch-menu-input/19519.html

Need help with a Batch File www.computing.net/answers/programming/need-help-with-a-batch-file/14580.html

Batch Menus www.computing.net/answers/programming/batch-menus/14362.html