Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何在批处理中组合IF语句_Batch File_Cmd - Fatal编程技术网

Batch file 如何在批处理中组合IF语句

Batch file 如何在批处理中组合IF语句,batch-file,cmd,Batch File,Cmd,我想把这一行放在我的批处理程序中: IF eventValue GTR 800 IF eventValue LEQ 805 SET eventEffect=tax 要么是我的语法错了,要么是别的什么东西错了。我的问题是,如果我希望事件值介于800和805之间,那么eventEffect设置为tax,这是正确的语法吗?或者是否有其他方法设置两个IF周长 提前谢谢 好吧,除了像@somethingDark提到的那样将它们变为变量之外,这里还有一些其他的选择 :: On one line with

我想把这一行放在我的批处理程序中:

IF eventValue GTR 800 IF eventValue LEQ 805 SET eventEffect=tax
要么是我的语法错了,要么是别的什么东西错了。我的问题是,如果我希望
事件值
介于
800
805
之间,那么
eventEffect
设置为
tax
,这是正确的语法吗?或者是否有其他方法设置两个
IF
周长


提前谢谢

好吧,除了像@somethingDark提到的那样将它们变为变量之外,这里还有一些其他的选择

:: On one line with parentheses:
if %eventValue% gtr 800 (if %eventValue% leq 805 (set eventEffect=%tax%))

:: Code blocks across multiple lines;
if %eventValue% gtr 800 (
    if %eventValue% leq 805 (
        set eventEffect=%tax%
    )
)

:: An odd, but occasionally useful in difficult code blocks check method;
set "isTax=true"
if not %eventValue% gtr 800 set "isTax=false"
if not %eventValue% leq 805 set "isTax=false"
if %isTax% equ true set eventEffect=%tax%

获得相同结果的不同方法:

set /A "test=0, aux=(800-eventValue)*(eventValue-805), test=(aux-1)/aux" 2>NUL
if %test% equ 0 echo The value is in 800-805 range
说明:

set /A (lowLimit-value)                            is negative or zero if value >= lowLimit
set /A (value-UpLimit)                             is negative or zero if value <= upLimit
set /A (lowLimit-val)*(val-UpLimit)                is positive or zero if value is in range,
                                                   negative otherwise, and
set /A aux=(Low-val)*(val-Up), test=(aux-1)/aux    set test=0 if value is in range,
                                                   test=1 otherwise
set/A(下限值)为负值,如果值>=lowLimit,则为零

set/A(value UpLimit)为负或零,如果值为零,您会得到什么错误?语法对我来说是正确的。我本身没有得到任何真正的“错误”,但程序会立即执行
echo%eventEffect%
echo%eventValue%
后缀,即使它符合参数,
eventEffect
也只会说它的默认字符串“nothing”变量名周围缺少
%
s<代码>如果%eventvalue%gtr 800如果%eventvalue%leq 805设置eventEffect=tax
。您可以发布您的全部代码吗?另外,您如何验证
eventValue
是否确实在范围内?你能添加一个
echo
语句来确定吗?@somethingsdark你是对的!!愚蠢的错误。谢谢