Need some help with a menu

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
leftybeaver128
Posts: 11
Joined: 24 May 2011 13:20

Need some help with a menu

#1 Post by leftybeaver128 » 21 Aug 2012 16:45

Hello all,
I'm having a bit of trouble getting my menu setup to work. When I select a choice, it just gives me the "Error. Please select a valid choice" text that I setup.

Can someone please tell me what's going wrong?

Thanks!

Here is a block of code that has the problem.

Code: Select all

:mainMenu
cls
echo ---Backup Manager----------
echo Version %VERSION%
echo.
echo.
echo Menu
echo ------
echo 1 View Current Backups
echo 2 Add a Backup
echo 3 Delete a Backup
echo 4 Legal
echo 5 Changelog
echo 6 Reinstall
echo Exit
echo.
set /p '%choice%'=(Please select an option)
if '%choice%'=='1' goto backupList
if '%choice%'=='2' goto backupAdd
if '%choice%'=='3' goto backupDelete
if '%choice%'=='4' goto legal
if '%choice%'=='5' goto changelog
if '%choice%'=='6' goto setup
echo Error, please select a valid choice.
pause>nul
goto mainMenu

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Need some help with a menu

#2 Post by abc0502 » 21 Aug 2012 16:59

replace all single qoute with double one

From

Code: Select all

if '%choice%'=='1' goto backupList

To

Code: Select all

if "%choice%"=="1" goto backupList


and this line

Code: Select all

set /p '%choice%'=(Please select an option)

to

Code: Select all

set /p "choice=(Please select an option)"


In Dos use double qoutes " " not ' '

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need some help with a menu

#3 Post by foxidrive » 21 Aug 2012 23:18

leftybeaver128 wrote:

Code: Select all

set /p '%choice%'=(Please select an option)


Remove the ' and % characters. You need to use a simple variable name here.


The double quotes are useful too:

set /p "choice=(Please select an option): "

Post Reply