Solved

Batch variable increment

Posted on 2001-06-11
3
6,216 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A few months ago I had an issue with LaserJet 1020 printer which was installed to XP and Windows 7.  It was installed to XP and working, but when I tried to connect from a Windows 7 PC, it would attempt connection and then fail.  Sometimes the Spool…
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 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now