1.

Solve : Set help?

Answer»

Hey

im trying to make its so that when you are given a choice in a set /P command
you can only do numbers. Is there an EASIER way to do this other than
going thru and putting "if equ a, if equ b...etc"

ex.

set /p a=Pick a number
if %a% equ a exit
if %a% equ b exit
...

making a only equal a number

There are a few ways to do this, here's one:

Code: [Select]set /p a=Pick a number
if %a% GEQ 0 if %a% LEQ 9 goto numeric
goto :eof
:numeric
.
.
.
and is it possible to set the number of digits for %random% ?Sort of.

one zero, single digit random number:

@ECHO off
set /a rnd=%random% / (32767 / 10)
echo %rnd%

two zeroes, double digit random number:

@echo off
set /a rnd=%random% / (32767 / 100)
echo %rnd%

three zeroes, three digit random number:

@echo off
set /a rnd=%random% / (32767 / 1000)
echo %rnd%


You can decide if this information has any value.




Discussion

No Comment Found