Now, I've seen a lot of people improperly make menus, so I've decided to make a quick tutorial on how to make a proper menu.
Making a menu is quite straight-forward. First, make a label. Let's call it, menu1.
Next is an important part of the menu. If the dumb user gives an incorrect option, what do you do? Add this code and the issue will be solved.
Now, the final code would be:
So, there it is. If you guys have any questions, comments, or concerns, speak freely.
Making a menu is quite straight-forward. First, make a label. Let's call it, menu1.
- Code:
:menu1
- Code:
echo 1. Option 1
echo 2. Option 2
echo 3. Exit
- Code:
set /p choice=Option ^(1/2/3^)
- Code:
REM - NUMERICAL OPTIONS -
if %choice%==1 goto option1
if %choice%==2 goto option2
if %choice%==3 exit
- Code:
REM - ALPHABETICAL OPTIONS -
if /i "%choice%"=="a" goto optionA
if /i "%choice%"=="b" goto optionB
if /i "%choice%"=="c" exit
Next is an important part of the menu. If the dumb user gives an incorrect option, what do you do? Add this code and the issue will be solved.
- Code:
cls
echo '%choice%' is an invalid option. Please try again.
REM The next line will change depending on what the original label is.
goto menu1
Now, the final code would be:
- Code:
REM - NUMERICAL MENU
:menu
echo 1. Option 1
echo 2. Option 2
echo 3. Exit
set /p choice=Option ^(1/2/3^)
if %choice%==1 goto option1
if %choice%==2 goto option2
if %choice%==3 exit
cls
echo '%choice%' is an invalid option. Please try again.
goto menu
- Code:
REM - ALPHABETICAL MENU
:menu
echo A. Option 1
echo B. Option 2
echo C. Exit
set /p choice=Option ^(A/B/C^)
if /i "%choice%"=="a" goto optionA
if /i "%choice%"=="b" goto optionB
if /i "%choice%"=="c" exit
cls
echo '%choice%' is an invalid option. Please try again.
goto menu
So, there it is. If you guys have any questions, comments, or concerns, speak freely.