对不起,但我得到的错误,可能包含我所有的代码。批处理文件额外迭代到只有一个标签
我做了两个文件,一个(rngInputTest)启动并检查执行循环,并通过call命令中的参数将四个变量传递给第二个(rngCompare)文件。
第二个文件然后将这四个参数保存到rngCompare的局部四个变量中,然后使用%random%两次。之后,它将两个新变量(rng1和rng2)设置为比较var,并将其传递回rngInputTest,并将其保存到var结果中。
rngInputTest然后做了最后的检查,如果checkLoop var是2,它会转到最终的标签/函数(rngInputTestDisplay),它的工作原理是,它回声良好。
我遇到的问题是,没有我的解决方法,在rngInputTestDisplay运行一次之后第二次执行到rngInputTestDisplay(没有调用其他标签/函数,并且第二次运行rngInputTestDisplay时,它会清空结果VAR)
我目前的解决办法是
IF %checkLoop%==%logicIII% goto :end
我把这个在rngInputTestDisplay的开始和停止额外的迭代。
没有解决办法,甚至把后:
echo in [label]
pause
在所有的标签/功能,rngInputTest和rngCompare
,我还是没能找出额外的迭代是如何发生的,虽然我没有注意执行循环只对rngInputTestDisplay执行。
这两个文件的最终目标是创建一个可重复使用的随机数,以便我可以多次调用第一个数据并将不同的数据集传递给它,然后将该数据返回给'main '文件。我知道我可以使用一次随机%%和拯救自己的头痛,但使用它一下后,它并没有真正感觉到随机
以下附上
两个文件rngInputTest.bat
@ECHO off
::increment the loop-check var
set /a checkLoop+=1
goto :initLoopCheck
::used to check for looping
:initLoopCheck
::before execution loops to rngCompare
set logicI=1
::after execution loops back from rngCompare
set logicII=2
::used in rngInputTestDisplay,phantom loop
set logicIII=3
::starts the initial loop
IF %checkLoop%==%logicI% goto :rngInputTestInitVarSet
::checks if code has looped back from rngCompare.bat
IF %checkLoop%==%logicII% goto :logic
::sets all the non-increment variables
:rngInputTestInitVarSet
::min-max's for use in rngCompare.bat :randomGen
set minI=0
set maxI=50
set minII=0
set maxII=50
goto :logic
::checks to see how far checkLoop has incremented
:logic
IF %checkLoop%==%logicI% goto :rngInputTestPass
IF %checkLoop%==%logicII% goto :rngInputTestDisplay
::passes min-max's to rngCompare via parameters
:rngInputTestPass
set checkLoop+=1
call rngCompare.bat %minI% %minII% %maxI% %maxII%
goto :rngInputTestDisplay
:rngInputTestDisplay
::this IF is important
::without it the code would loop..only to
:: :rngInputTestDisplay
::which causes result to be empty
IF %checkLoop%==%logicIII% goto :end
set /a checkLoop+=1
set result=%~1
echo result:%result%
pause
:end
rngCompare.bat
@ECHO off
goto :rngCompareInitVarSet
::initial variable set
:rngCompareInitVarSet
set MaxI=0
set MaxII=0
set MinI=0
set MinII=0
set result=0
goto :afterPass
::after rngInputTestPass
:afterPass
set MinI=%~1
set MinII=%~2
set MaxI=%~3
set MaxII=%~4
goto :randomGen
::generate two random numbers
:randomGen
::gets two random numbers from the variables passed from rngInputTest.bat
set /a rngI=(%RANDOM%*%MaxI%/32768)+%MinI%
set /a rngII=(%RANDOM%*%MaxII%/32768)+%MinII%
goto :compareRNG
::add the two rng numbers
:compareRNG
::adds the two numbers together
set /a compare=%rngI%+%rngII%
goto :passToRNGInputTest
::pass the compare var back to rngInputTest
:passToRNGInputTest
call rngInputTest.bat %compare%
呃。你有递归(A调用B调用A)。但我不认为这是你想要的。 “rngCompare.bat”shoud * return *(EXIT/B)返回调用者“rngInputTest.bat”。它应该*不*递归调用“rngInputTest.bat”。 – dbenham