0

Hey I'm working on a project of mine in batch. yes I know its bad but I'm using it anyways. I was trying to make an updating inventory system when I ran into this problem. I was trying to add a set number E.X 1 to a variable like this:

@echo off
set var=0
echo I will add these numbers from var+1
set /a var=%var%+1
pause
echo var
pause

what is the problem?

4
  • 3
    There is a simpler form to add to a var with Set /a var+=1 and also with set /a there is no need to enclose the var wih percent signs (aside from ! and delayed expanasion) I suggest readinghelp set Commented Nov 11, 2016 at 1:02
  • 1
    set /? isn't going to mention the alternate variation of set /a that you're talking about. Commented Nov 11, 2016 at 3:09
  • thanks that helps a lot. I got my program working! thanks again Commented Nov 11, 2016 at 3:12
  • @SomethingDark cited from Set /? Any non-numeric strings in the expression are treated as environment variable names whose values are converted to numbers before using them. If an environment variable name is specified but is not defined in the current environment, then a value of zero is used. This allows you to do arithmetic with environment variable values without having to type all those % signs to get their values. Commented Nov 12, 2016 at 12:19

1 Answer 1

2

To show the value of the variable var, you need

echo %var%
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.