Computing.Net > Forums > Programming > Batch File Counter Increment

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.

Batch File Counter Increment

Reply to Message Icon

Name: zrm0008
Date: September 10, 2008 at 11:02:40 Pacific
OS: XP
CPU/Ram: 1.7 ghz/2 gig
Product: IBM
Comment:

Is it possible to increasement an integer counter in a batch file script? Example:

Set Sleep=0
:Rerun
osql ...
if %ERRORLEVEL%==0 goto :Cont
Set Sleep=%Sleep%+1
if %Sleep%==3 goto :ErrorOut
goto :Rerun
:ErrorOut
exit %ERRORLEVEL%
:Cont
...

Basically, I need to run a SQL Server Stored Procedure until it successfully runs before I want the script to error out. Currently, the result for %SLEEP% will be '0+1' after the code above runs, not 1. Can anyone help?



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: September 10, 2008 at 11:38:09 Pacific
Reply:

Rewrite your code as below

Set Sleep=0
:Rerun
osql ...
if not ErrorLevel 1 goto :Cont
Set /A Sleep+=1
if %Sleep% lss 3 goto goto :Rerun
exit %ErrorLevel%
:Cont
...


0

Response Number 2
Name: zrm0008
Date: September 10, 2008 at 14:30:30 Pacific
Reply:

Worked like a charm. I love it when there are people smarter then I am out there that don't mind helping out. Thanks!!


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 Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File Counter Increment

Batch file name incrementing www.computing.net/answers/programming/batch-file-name-incrementing/14959.html

Batch file counter www.computing.net/answers/programming/batch-file-counter/19865.html

batch file to copy & increment www.computing.net/answers/programming/batch-file-to-copy-increment/18184.html