本文介绍了如果GTR / LSS运营商在批量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用 GTR
/ LSS
运营商越来越大的批处理文件。问题是,在如果
语句只允许我进入某些值。在下面的示例,在2,3或4的值输入将返回值过高。
I have an increasingly large Batch file that uses GTR
/LSS
operators. The problem is that the if
statements only permit me to enter certain values. In the following exemplar, typing in values of 2, 3 or 4 will return "Value too high."
:char_intb
set char_points=30
set /a limit=!char_points!-3
set /p char_int="How many points for intelligence? "
if "!char_int!" GTR "!limit!" echo Value too high. && goto char_intb
if "!char_int!" GTR "!char_points!" echo Insufficient points. && goto char_intb
if "!char_int!" LSS "1" echo Select a value greater than or equal to 1. && goto char_intb
set /a char_points=!char_points!-!char_int!
echo You now have !char_points! remaining.
有别人。至于我测试过,它似乎只允许我键入0或11
There are others. As far as I've tested, it seems to only allow me to type 0 or 11.
set /p char_month="Month (0-11): "
if "!char_month!" GTR "11" echo Enter a value between 0 and 11. && echo. && goto last_char
我在哪里去了?
推荐答案
不要使用双引号!char_month! GTR十一
对于数字比较,在这种情况下 CMD
会做的字符串比较。这应该工作:
Do not use double quotes "!char_month!" GTR "11"
for numeric compare, in this case cmd
will do a string compare. This should work:
@ECHO OFF &SETLOCAL
:last_char
set /p "char_month=Month (0-11): "
if %char_month% GTR 11 (
echo Enter a value between 0 and 11.
echo.
goto last_char
)
ECHO %char_month%
这篇关于如果GTR / LSS运营商在批量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!