• Please review our updated Terms and Rules here

DOS Batch: A Simple Counter

ZonerZone

New Member
Joined
Apr 18, 2007
Messages
1
I wrote a little batch file (OS=XP) that just counts from 1-4, in increments of +1, each time the batch file is run. It counts fine, except it doesn't stop at 4, but keeps counting indefinitely.
I think the problem might be in the second IF statement. Either:
(a) the condition is not reading the number, and/or
(b) the command to reset the number to 0 is not working.
I can't get the syntax of this line right or something?:
----------------------
@ echo off
echo %number% <--(just a checker)
If exist ZZtrash.bat call ZZtrash

If "%number%"=="4" set number=0

echo %number% <--(just a before-checker )
set /a number=number+1
echo %number% <--(just an after-checker )
echo set number=%number% >ZZtrash.bat
pause
----------------------
How can I get it to reset to '1' after counting to '4' when I run the batch the 5th time?
Any help here would sure be appreciated!
ZonerZone
 
Back
Top