Solved

Batch variable increment

Posted on 2001-06-11
3
6,227 Views
Last Modified: 2013-12-28
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
Comment
Question by:j_k
3 Comments
 
LVL 7

Expert Comment

by:jjeff1
ID: 6179467
http://www.zdnet.com/pcmag/issues/1511/pcmg0088.htm

Hows that? It will take a bit of tweaking, but should work for you.
0
 
LVL 3

Accepted Solution

by:
czpczp earned 50 total points
ID: 6181046
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
 

Author Comment

by:j_k
ID: 6181419
Just what I needed.  Thanks.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question