user2037860
user2037860

Reputation: 25

Math. Batch (missing operand, or missing operator)

set /a var=2
(
    set /a %var%=var * 2
    set /a %var%=%var% * 2
    set /a %var%*= 2
)

Why does it say its wrong?

I got messages like Missing operand and Missing operator. Well, operator is there, though I don't know what's operand.

Yes I searched for answer in here, but non of all solves... St least ones that I saw.

Upvotes: 1

Views: 18313

Answers (3)

Endoro
Endoro

Reputation: 37569

Thats all :)

set /a var=2
set /a var*=2

..value of %var% is 4.

see operand

Upvotes: 2

Ken White
Ken White

Reputation: 125718

You're misusing the % syntax. % means expand the contents of this variable, which is not what you want to do. You want to store the result of the calculation back into the variable. Just remove the % on the left side of the assignment operator.

Try this instead:

set /a var=2
@echo %var%
set /a var=%var% * 2
set /a var=%var% * 2
set /a var*= 2
@echo %var%

Upvotes: 2

user2371381
user2371381

Reputation:

I believe, that %var% is syntax for interpreter (shell) and it replaces %var% with value of that variable. And it should happen before any command is called. Set works with environment variables, so it has to work with them and not their values. Try set /a var = 2; set /a var = var * 2. By the way, in "4 + 5" + is the operator and 4,5 are operands (arguments of operator).

Upvotes: 0

Related Questions