I need the help of a Batch macro expert
I tried to write a macro, called WHILE, to make good use of this trick in an easier way. I first wrote a subroutine that works ok. When I convert it to a macro I got an error in the line with the REM below:
::Above 2 blank lines are required - do not remove
set while=for %%n in (1 2) do if %%n==2 (%\n%
call :StrLen argv argvLen=%\n%
call :StrLen body bodyLen=%\n%
set /A condLen=argvLen-bodyLen-2%\n%
for %%a in (!condLen!) do set "cond=!argv:~0,%%a!"%\n%
REM echo for /L %%%%w in (1,0,1) do if !cond! !body! else call whileBreak^> whileBody.bat%\n%
echo for /L %%%%w in (1,0,1 do if !cond! !body! else call whileBreak^> whileBody.bat%\n%
echo exit %%whileResult%%^> whileBreak.bat%\n%
cmd /Q /C whileBody%\n%
endlocal ^& set whileResult=^!errorlevel^!%\n%
) else setlocal EnableDelayedExpansion ^& set argv=
%while% %!%num%!% leq 10 do (%\n%
set /A whileResult+=num%\n%
set /A num+=1%\n%
echo While result: %whileResult%
:StrLen string [result=[adjust]]
set str=!str:"= !
if "!str:~0,1!" == " " (
) else (
for /L %%A in (12,-1,0) do (
set /A "len|=1<<%%A"
for %%B in (!len!) do if "!str:~%%B,1!" == "" set /A "len&=~1<<%%A"
for %%v in (!len!) do endlocal&if not "%2" == "" (set /A "%2=%%v%3") else echo %%v
The error is "do was unexpected at this time". I made several tests and discovered that the right parentheses of the "FOR ... IN (1,0,1)" is really closing THE IF %%N==2 (
of the macro definition
The line below the FOR don't cause the error, but the whileBody is not completed correctly.
I can't discover the cause of this error. HELP ME, PLEASE!