Batch Beta
Please Login to get full access and to disable ads.

Thanks to awestom for removing those ads!

Staff Selections are closed! Thanks for participating!
Welcome to the new admins and mods!
About the ads, yeah. We reached our 250'th post and the ads kicked on. In order to disable them I need to purchase a ad removal feature. Now, I don't have credits and in order to get one I need donations. Thanks

You are not connected. Please login or register

How to properly make a menu

Go down  Message [Page 1 of 1]

1 How to properly make a menu on Thu Jan 13, 2011 4:30 pm

Forum_Reader

avatar
Jr Admin
Jr Admin
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.
Code:
:menu1
Now, you need to display the options. Let's make 3.
Code:
echo 1. Option 1
echo 2. Option 2
echo 3. Exit
Then you need to get user input.
Code:
set /p choice=Option ^(1/2/3^)
This is the part that most people mess up on: properly executing commands depending on the user's choice. If you are using alphabetical options instead of numerical, use the code from the next code box.
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
You may notice that I didn't add options for capital letters. That's what the /i switch is for. It means case-insensitive. That means it will compare the two items, but disregard case.
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.

2 Re: How to properly make a menu on Thu Jan 13, 2011 4:46 pm

-xPloit

avatar
Moderators
Moderators
I think a good point to emphasize here is that the "graphical menu" is not literally a menu. If you have too many items on your menu, it becomes bothersome to scroll up and down trying to find what you want. You can, to make things easier, double them up. Make the menu 2x wider and therefore, 2x shorter. But the code for managing the selection would still be the same

For example:
Code:

echo 1) This is option 1
echo 2) This is option 2
echo 3) This is option 3
echo 4) This is option 4

can be written as:
Code:

echo 1) This is option 1          3) This is option 3
echo 2) This is option 2          4) This is option 4

and the set /p choice code would still work exactly the same. It's something I've noticed with people and their menus...they put a menu of 20+ items and it's in a 1x20 grid, rather than 5x4 or something scratch

Good tut FR ^^ just had to add my 2 cents worth haha


_________________
00101101011110000101000001101100011011110110100101110100

C# \ VB Coder for hire


Click the banner to join!

3 Re: How to properly make a menu on Thu Jan 13, 2011 5:07 pm

Forum_Reader

avatar
Jr Admin
Jr Admin
-xPloit wrote:I think a good point to emphasize here is that the "graphical menu" is not literally a menu. If you have too many items on your menu, it becomes bothersome to scroll up and down trying to find what you want. You can, to make things easier, double them up. Make the menu 2x wider and therefore, 2x shorter. But the code for managing the selection would still be the same

For example:
Code:

echo 1) This is option 1
echo 2) This is option 2
echo 3) This is option 3
echo 4) This is option 4

can be written as:
Code:

echo 1) This is option 1          3) This is option 3
echo 2) This is option 2          4) This is option 4

and the set /p choice code would still work exactly the same. It's something I've noticed with people and their menus...they put a menu of 20+ items and it's in a 1x20 grid, rather than 5x4 or something scratch

Good tut FR ^^ just had to add my 2 cents worth haha
Very smart!

4 Re: How to properly make a menu on Fri Jan 14, 2011 11:27 am

-xPloit

avatar
Moderators
Moderators
i know, I'm a genius ^^


_________________
00101101011110000101000001101100011011110110100101110100

C# \ VB Coder for hire


Click the banner to join!

Sponsored content


Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum