• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6261
  • Last Modified:

Batch variable increment

Is it possible to increment a variable by 1 in a batch file? (Winnt 4.0).  For example, if COUNT is currently 100000, increment COUNT to be 100001.

1 Solution

Hows that? It will take a bit of tweaking, but should work for you.
Hi j_k.  The easiest way to do this is to use the SET and For statements in tandem.  There's many things you can do here.  Based on the information you provided, this batch will increment the variable Count (who's value is 100000) by 1.  If you wanted to count up to we'll say 100050 then in the For statement, change (1,1,1) to (1,1,50) and so on.

@echo off

Set /a Count=100000
for /L %%i IN (1,1,1) DO set /a Count=%Count% + %%i
echo %Count%

Like I said, there's many things you can do here (and many ways to accomplish this).  To simply increment by one you can use:

Set /a Count=100000
.   The next Set statement could appear later in a batch
Set /a Count=%Count% + 1

If you need further info, please provide feedback.
j_kAuthor Commented:
Just what I needed.  Thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now