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! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to 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




Sponsored Link
Ads by Google

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

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

Batfiles: The DOS batch file programming handbook



0

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

You need to add the /a with set.

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

Regards

Simon


0

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

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


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