Missing operator???

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Missing operator???

#1 Post by tinfanide » 15 Apr 2012 08:46

Code: Select all

@ECHO ON

SET base=3
SET power=3

FOR /L %%A IN (1,1,%power%) DO CALL :Count %%A
PAUSE
GOTO :EOF

:Count index
SET /A times=%1-1
IF NOT %times%==0 (
   CALL :ToPower %base% %times%
   SET /A skip=10-%n%
   ECHO %skip%

)
PAUSE
GOTO :EOF

:ToPower
SET n=1
FOR /L %%C IN (1,1,%2) DO SET /A n*=%1
GOTO :EOF

PAUSE


C:\test>SET base=3

C:\test>SET power=3

C:\test>FOR /L %A IN (1 1 3) DO CALL :Count %A

C:\test>CALL :Count 1

C:\test>SET /A times=1-1

C:\test>IF NOT 0 == 0 (
CALL :ToPower 3 0
SET /A skip=10-!n!
ECHO
)

C:\test>GOTO :EOF

C:\test>CALL :Count 2

C:\test>SET /A times=2-1

C:\test>IF NOT 1 == 0 (
CALL :ToPower 3 1
SET /A skip=10-!n!
ECHO
)

C:\test>SETLOCAL ENABLEDELAYEDEXPANSION

C:\test>SET n=1

C:\test>FOR /L %C IN (1 1 1) DO SET /A n*=3

C:\test>SET /A n*=3

C:\test>GOTO :EOF
Missing operator.
ECHO is on.

C:\test>GOTO :EOF

C:\test>CALL :Count 3

C:\test>SET /A times=3-1

C:\test>IF NOT 2 == 0 (
CALL :ToPower 3 2
SET /A skip=10-!n!
ECHO 9
)

C:\test>SETLOCAL ENABLEDELAYEDEXPANSION

C:\test>SET n=1

C:\test>FOR /L %C IN (1 1 2) DO SET /A n*=3

C:\test>SET /A n*=3

C:\test>SET /A n*=3

C:\test>GOTO :EOF
Missing operator.
9

C:\test>GOTO :EOF

C:\test>ENDLOCAL

C:\test>PAUSE
Press any key to continue . . .


Simple maths. But just don't know why it causes errors.
Please help!

tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Re: Missing operator???

#2 Post by tinfanide » 15 Apr 2012 08:51

Thanks to aGerman in the previous post.
SETLOCAL ENABLEDELAYEDEXPANSION does expand the run-time variable, if the wordings are correct technically.

Code: Select all

@ECHO ON
SETLOCAL ENABLEDELAYEDEXPANSION

SET base=3
SET power=3

FOR /L %%A IN (1,1,%power%) DO CALL :Count %%A
ENDLOCAL
PAUSE
GOTO :EOF

:Count index
SET /A times=%1-1

IF NOT %times%==0 (
   CALL :ToPower %base% %times%
   SET /A skip=10-!n!
   ECHO !skip!

)

GOTO :EOF

:ToPower

SET n=1
FOR /L %%C IN (1,1,%2) DO SET /A n*=%1

GOTO :EOF

Cat
Posts: 32
Joined: 11 Nov 2011 12:04

Re: Missing operator???

#3 Post by Cat » 15 Apr 2012 22:49

Is this just trying to do exponents? Either try "exit /b" for "GOTO :EOF" or:

Code: Select all

@echo off
set base=3
set mult=%base%
set power=3
for /l %%a in (2,1,%power%) do set /a mult*=%base%
echo %mult%
pause

Both ideas untested, though.

tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Re: Missing operator???

#4 Post by tinfanide » 16 Apr 2012 05:23

Cat wrote:Is this just trying to do exponents? Either try "exit /b" for "GOTO :EOF" or:

Code: Select all

@echo off
set base=3
set mult=%base%
set power=3
for /l %%a in (2,1,%power%) do set /a mult*=%base%
echo %mult%
pause

Both ideas untested, though.


Yes, tested. It works. Thank you.
Based on your script that makes me simplify it, here's mine:

Code: Select all

@echo off
set base=3
set power=3
Set /A init=%power%-1
for /l %%a in (%init%,1,%power%) do set /a base*=%base%
echo %base%
pause

Post Reply