I would like to add special characters like <
|
into my choice command, how can I do that?
Here's my old code:
CHOICE /C ABCDEFGHIJKLMNOPQRSTUVWXYZ0134567928 /N /M "Press 8 ...."
and I would like it to be something like :
CHOICE /C `~,.<>?ABCDEFGHIJKLMNOPQRSTUVWXYZ0134567928 /N /M "Press 8 ...."
Any help will be appreciated, thanks.
EDIT: Since some of you may ask why do I need so many choice, I'm here to answer. It is because pressing an invalid choice would give you an annoying beep that I would not like. Therefore I asked this question.
Th9is is a VBS file.
The CHOICE command only allows alpha-numeric characters, as well as extended ASCII characters with decimal byte codes between 128-254.
I have written a pure batch substitute for CHOICE based on a hack that uses REPLACE. My
:getKey
routine can accept most any character, and allows you to specify the allowed characters, and it puts the captured character in a variable of your choosing - much more convenient than messing with ERRORLEVEL.I originally posted the routine at http://www.dostips.com/forum/viewtopic.php?f=3&t=7396. The link also has a more complicated routine that can read absolutely any key value, including NULL, as well as a routine that allows input of a masked string (displays asterisks for each character).
Below is the :getKey routine, along with an example showing usage. Remove the
/I
switch if you want the keys to be case sensitive. Full documentation is embedded within the script.Edit - I've updated the code to version 2.0 with the ability to specify a prompt, and to have the valid key list be case sensitive. The only CHOICE feature that cannot be emulated is a timeout option with a default response. I don't see any reasonable way to ever provide a timeout option.
Using Choice, you cannot.
If you attempt to execute Choice with an invalid character, you will get a message. For example (caret '^' symbol is to escape the pipe '|', as this is a special character for cmd):
returns:
ERROR: Invalid choice. The valid choice characters are: a-z, A-Z, 0-9 and ASCII values of 128 to 254.
Possible workaround:
You can possibly use SET to accomplish your needs, but then you are working with variables in a batch script that could potentially cause problems. Anywhere that you would use these variables, you will need to preceed with the escape character caret (^).
This solution would also require that the user hit the enter key after making their selection.