Article View: comp.os.msdos.misc
Article #3959Re: [Q] calculation in batch file
From: John Savage
Date: Thu, 28 Sep 1995 00:00
Date: Thu, 28 Sep 1995 00:00
70 lines
3116 bytes
3116 bytes
liwan@wam.umd.edu (Li-Wan Chen) writes:
>I need write a batch file, that is a loop and calculate up to 100 then go
>out. Can someone tell me how to do it? Thank you
If you wish to use an environment variable, I can think of three approaches:
(a) use the arithmetic option of a multi-function batch utility, e.g., GET
(b) use an executable which performs the task, e.g., INCR.COM
(c) use a pure-DOS batch file, e.g., INCR.BAT
Example (a), GET25.EXE
----------------------
@ECHO OFF
SET COUNTER=0
:LOOP
GET R %COUNTER% /W1 /VCOUNTER=
REM ...
REM ...
IF NOT %COUNTER% == 300 GOTO LOOP
GET25 does not preserve leading zeros, though its other functions can be
brought into play to restore the appropriate number of leading zeros.
Example (b), INCR.COM
---------------------
SET I=0
:LOOP
INCR I
REM ...
REM ...
IF NOT %I% == 30 GOTO LOOP
Note that INCR.COM does not preserve leading zeros, they are discarded.
You can obtain INCR.COM as a 5k file packaged in with RBSETNV1.
Example (c), INCR.BAT
---------------------
Usage is identical with (b), except requires SET I=00 and the end point
will require IF NOT %I%==00 GOTO LOOP because it is a two-digit counter.
@echo off
echo set val=%%%1%%>d:1.bat
call d:1
for %%i in (/%val%) do set d2=%%i
set d1=%d2%
for %%i in (/%val%) do if not %%i==%d2% set d1=%%i
echo set d2=%%%d2%%%>d:1.bat
if not %d2%==9 goto RR
echo set d1=%%%d1%%%>>d:1.bat
:RR
D:
call 1 2 3 4 5 6 7 8 9 0
C:
set %1=%d1%%d2%
for %%i in (d1 d2 val) do set %%i=
INCR.BAT needs 2-digit counter initialization, counts 00-99, & returns to 00.
INCR.BAT creates its own work file, so it is best that you have a RAM drive.
Note that INCR.BAT differs from (b) in that leading zeros are now preserved.
Also I have a .BAT which will increment numbers of up to 9 digits, if needed.
ftp ftp.cdrom.com /pub/garbo/garbo_pc/envutil/
rbsetnv1.zip Setenv & eval environment variables (w C)
ftp ftp.cdrom.com /pub/garbo/garbo_pc/batchutil/
get25.zip General batch enhancer incl. keyboard, src, disk, mem utils
--
John Savage koala@sydney.dialix.com.au
Technical Details
Message-ID:
<44e15j$gr5$1@sydney.DIALix.oz.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<43cp7q$o4c@cville-srv.wam.umd.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d683,c24e324db3069542,start X-Google-Attributes: gid10d683,public X-Google-Thread: f53ba,c24e324db3069542,start X-Google-Attributes: gidf53ba,public X-Google-Thread: 1674b9,c24e324db3069542,start X-Google-Attributes: gid1674b9,public X-Google-Thread: f71eb,cd5a8f4c774b7136 X-Google-Attributes: gidf71eb,public X-Google-Thread: 111d31,c24e324db3069542,start X-Google-Attributes: gid111d31,public From: John Savage <koala@sydney.dialix.com.au> Subject: Re: [Q] calculation in batch file Date: 1995/09/28 Message-ID: <44e15j$gr5$1@sydney.DIALix.oz.au> X-Deja-AN: 110918606 sender: koala@sydney.DIALix.oz.au references: <43cp7q$o4c@cville-srv.wam.umd.edu> organization: Gumleaf Smoke Signals Telegraph Company newsgroups: comp.os.msdos.misc,comp.binaries.ibm.pc.wanted,comp.archives.msdos.d,comp.sys.ibm.pc.misc,aus.computers.ibm-pc