1.

Solve : CHOICE vs. SET command?

Answer»

I want to use BATCH files to allow a Yes/no prompt e.g. "Do you wish to continue? (Y/N)" but I am having trouble. I saw the CHOICE command, and tried it, but since I am using Version 5.1, I can't use it. This site says the SET command can be used the same way, but I can't figure out how to use the SET command in the same way. It doesn't seem to fit what the CHOICE command is capable of. And I don't know how to write code like this: I'm not a genius PROGRAMMER! Can anyone please tell me how to use SET this way?Code: [Select]
set /p var=promptstring


Use the %var% variable in your batch file as needed. Note: Choice only allowed ONE byte responses and used errorlevels. Set does not use errorlevels and response lengths are only limited by the size of the environment space.

Hope this helps. Well, I don't get BAD COMMAND OR FILE NAME anymore, but what comes after that line? I'm just learning, so I'm building a TEST.BAT. I want to make it so when you type 1, you GOTO 1, then 2, and so on. Could you please type up a sample text with such a SET command? I apologize, but I haven't used DOS for 12 years.This is about as simple as it gets. Perfect for a Wednesday afternoon.

Code: [Select]
@echo off
set /p var=Enter Option
goto %var%
:1
echo 1
goto end
:2
echo 2
goto end
:3
echo 3
goto end
:4
echo 4
:end


Good luck. Boy, I am a newbie, after all!

I looked at an example of SET and it said a bunch of stuff about things I could never remember. This is much easier. Thanks!

My lack of understanding just might have something to do with the fact I'm 14. Oh, well. Back to the typing board.Quote

I apologize, but I haven't used DOS for 12 years.


Quote
My lack of understanding just might have something to do with the fact I'm 14


Huh?What I just said is that I am 14 years old. I'm young, and didn't use more that a little of DOS growing up, since Windows came out. At least, that's when I GOT it.

Actually, I had one more question. In that example, what if someone types 5? That's not a choice, so it terminates the .BAT file. How do I get it to return to the beginning?That's one of the problems with set. Choice only allowed you to enter a defined response and otherwise beeped if you did not.

Code: [Select]
@echo off
:start
set /p var=Enter Option:
if %var%==1 goto 1
if %var%==2 goto 2
if %var%==3 goto 3
if %var%==4 goto 4
goto start
:1
echo 1
goto end
:2
echo 2
goto end
:3
echo 3
goto end
:4
echo 4
:end


Not nearly a clean as CHOICE, but it gets the JOB done. Thank you. I suppose that's it. I'll get back to learning some more advanced functions of DOS. Have a good day, Sidewinder.


Discussion

No Comment Found