• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6257
  • 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.

Thanks.
0
j_k
Asked:
j_k
1 Solution
 
jjeff1Commented:
http://www.zdnet.com/pcmag/issues/1511/pcmg0088.htm

Hows that? It will take a bit of tweaking, but should work for you.
0
 
czpczpCommented:
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
cls

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.
0
 
j_kAuthor Commented:
Just what I needed.  Thanks.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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