Menus in one batch file 03-06-2014, 05:25 AM
#1
My example of menus in batch files, using two different menus in one file. This is geared towards people who are just starting to learn batch.
REM is a comment line, it has no effect on the operation of the code. @Echo off is a code that is essential to scripts where you don't want the user to see the commands themselves. Echo prints stuff on the screen that you want it to. Lines starting with : represent bookmarks, and you can essentially make them anything you want, but don't use spaces unless you want to "" after goto. Goto refers to and jumps to bookmarks, signaled by : lines. Set /P actually controls the menu, A or B as in "set /p A=..." Sets the user's response to the A variable, and after the = it prints that to the user. If %A%==# states that if the user response is that number, it will do the command after it. To make it easier I used goto.
Sorry if it was too simple, was just trying to make a contribution to the forum.
REM is a comment line, it has no effect on the operation of the code. @Echo off is a code that is essential to scripts where you don't want the user to see the commands themselves. Echo prints stuff on the screen that you want it to. Lines starting with : represent bookmarks, and you can essentially make them anything you want, but don't use spaces unless you want to "" after goto. Goto refers to and jumps to bookmarks, signaled by : lines. Set /P actually controls the menu, A or B as in "set /p A=..." Sets the user's response to the A variable, and after the = it prints that to the user. If %A%==# states that if the user response is that number, it will do the command after it. To make it easier I used goto.
Sorry if it was too simple, was just trying to make a contribution to the forum.
Code:
REM Sample batch menu.
@Echo off
:mainmenu
cls
echo This is the main menu.
echo Use the keyboard to select an option below.
echo 1. Menu 2
echo 2. Exit Batch
set /p A=Press 1 or 2 and then press enter.
IF %A%==1 goto menu2
IF %A%==2 goto end
:menu2
cls
echo This is the second menu
echo 1. Notepad
echo 2. Back to Main Menu
echo 3. Exit Batch
set /p B=Press 1, 2, or 3 and press enter.
IF %B%==1 goto notepad
IF %B%==2 goto mainmenu
IF %B%==3 goto end
:notepad
cls
notepad
goto menu2
:end

![[+]](https://sinister.li/images/modern/collapse_collapsed.png)
















