Tip & How-To about Computers & Internet

How to use the set command as a substitute for the choice command in W2K an XP

The choice command from Win95 can't be used in WinXP or W2K you need to use the SET CHOICE = and the IF'%CHOICE%'== command here is the same example for Win95 example with the CHOICE and ERRORLEVEL commands.

Example One: (Win95)

In the below example a user would be prompted to enter an option of y,n, or Q to print you have selected YES , NO, or QUIT.

@ECHO OFF
:BEGIN
CLS
CHOICE /N /C:ynQ Select (y,n or Q)? %1
IF ERRORLEVEL ==3 GOTO QUIT
IF ERRORLEVEL ==2 GOTO NO
IF ERRORLEVEL ==1 GOTO YES
GOTO END
:QUIT
ECHO YOU HAVE PRESSED QUIT
GOTO END
:NO
ECHO YOU HAVE PRESSED NO
GOTO END
:YES
ECHO YOU HAVE PRESSED YES
:END


To add more choices increase the errorlevel number and append to the ynQ on the choice command

Example 2: (WinXP and W2K)

In the below example a user would be prompted to enter an option of y,n, or Q to print you have selected YES , NO, or QUIT.

@echo off
cls
:start
echo.
set choice=
set /p choice=Type (y,n or Q)?
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='y' goto yes
if '%choice%'=='n' goto no
if '%choice%'=='Q' goto quit
echo "%choice%" is not valid please try again
echo.
goto start
:yes
echo you have selected YES
goto end
:no
echo you have selected NO
goto end
:quit
echo you have selected QUIT
goto end
:end

To add more options simply add another if '%choice%'== goto line and give it a name and add the colon to the front of the name.


Hope this helps took me a whole night to work it out for Windows XP I like the way it works its much easier to understand when you don't have to use the ERRORLEVEL.

N.B> I have used 3 options Y,N or Q you don't have to and the choice I have kept simple you can copy this code and add your own replace the (you have selected YES) with whatever you require to happen if the user presses Y.

Posted by on

Computers & Internet Logo

Related Topics:

Related Questions:

1 Answer

need to set time on new watch


Impossible to answer your question without more information.

Use the Comment menu choice to add information, for example, make and model of watch.

May 01, 2018 | Watches

2 Answers

How to Delete Read Only Files?


Turn off the read-only attribute. Right-click the file in your operating system's file browser and select the appropriate choice.

Oct 18, 2016 | Computers & Internet

1 Answer

There is a PC made by myself ,it is included MSI482M-IL. Now it is W2K. I want to install W-XP. I tried install that,but I can't. Becuase always PC set up W2K. I can't boot control in this BIOS. How do I install W-XP? Please help me ,please,sir..


go to bios setting first, then at boot device select boot from cd at first, then press f10 to save then enter, pc will reboot, insert winxp cd then press any key at "press any key to boot from cd" appear then follow instruction that shown after that
i hope this helpfull, please rate very helpfull if you think this helpfull
thanks for using fixya

Jan 22, 2011 | MSI RS482M-IL (7145060RS482MIL)...

1 Answer

Started blinking on off after standby. Restarted cpu it worked fine di the same thing after standby again now it lashes on/off even when the cpu is off


1 •Click on the Windows Start menu and go to Control Panel.
•Step 2
Click the "Power Options" choice located inside Windows Control Panel. The choices are listed in alphabetical order. A photo example of this
button is located within this article.
•Step 3
Power Options Properties Dialog Box in Microsoft WindowsClick on the first drop down box, which displays "portable" or "desktop" types of
power scheme choices. Select the one that best suits your computer use even if it is not a desktop or laptop. Doing this will not adversely affect
your computer.
•Step 4
Turn off monitor time options example menuClick on the "Turn Off Monitor" options and select your desired time limit from the drop down box.
You can feel free to select "never" for this choice and any of the others. One column displays "Running on Batteries" while the other displays
"plugged in options." Your selections can be different for each. Make your choices according to your use and preferences of your own
computer. A photo example is shown within this article.
•Step 5
Turn off Hard disks exampleClick the "Turn off Hard Disks" choice if you would like to change the timing of that.
•Step 6
System Standby choicesClick on "System Standby" and make any changes to the time limits as needed. This is optional. It may be best to select
"never" or at least a few hours for this choice.
•Step 7
System HibernateClick "System Hibernates" if you wish to have your computer hibernate (or "sleep") after a certain length of time. This again is
entirely optional and not required. When you are finished, click "OK" to save all of your choices. This is very important.

Jun 11, 2010 | Computers & Internet

Not finding what you are looking for?

1,126 people viewed this tip

Ask a Question

Usually answered in minutes!

Top Computers & Internet Experts

Ekse

Level 3 Expert

13434 Answers

Marvin
Marvin

Level 3 Expert

85216 Answers

Brad Brown

Level 3 Expert

18127 Answers

Are you a Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Loading...