Computing.Net > Forums > Disk Operating System > Incrementing a numeric value in a batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Incrementing a numeric value in a batch file

Reply to Message Icon

Name: Greg
Date: February 14, 2001 at 08:44:28 Pacific
Comment:

Hi,

All,

This should be a simple exercise,
but I can't seem to figure it out.
I'm creating a DOS batch file to run under Win9x
and am trying to increment a counter variable (Qnum)
sequentially in response to a receiving a carriage
return.

Batch code:
set Qnum = 0
if %ANS% == "" goto SeqQ
set Qnum=%ANS%
goto NextQ
:SeqQ
set Qnumt=%Qnum%
set Qnum=%Qnumt%+1
echo %Qnum%

What is wrong?
TIA - Greg





Response Number 1
Name: Laurence
Date: February 14, 2001 at 12:48:56 Pacific
+1
Reply:

See here:
http://home7.inet.tele.dk/batfiles/main/showcase.htm#savage

Batfiles: The DOS batch file programming handbook




Response Number 2
Name: Simon Altaf
Date: June 20, 2001 at 00:36:12 Pacific
+1
Reply:

You need to add the /a with set.

so to increment do:
Set /a set Qnum=%Qnumt%+1

Regards

Simon



Response Number 3
Name: Simon Altaf
Date: June 20, 2001 at 00:37:26 Pacific
+1
Reply:

sorry there was a typo
set /a Qnum=%Qnumt%+1



Reply to Message Icon

Related Posts

See More


Concurrent dos 3.1 problem in starting windo...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Google Ads



Results for: Incrementing a numeric value in a batch file

%1 in a batch file www.computing.net/answers/dos/1-in-a-batch-file/13916.html

User log in date from a batch file www.computing.net/answers/dos/user-log-in-date-from-a-batch-file/7783.html

Dos Commands in a batch file www.computing.net/answers/dos/dos-commands-in-a-batch-file/1258.html