Computer Hope

Microsoft => Microsoft DOS => Topic started by: Woofy613 on September 14, 2008, 09:17:12 PM

Title: DOS Batch File - Incrementing in Loops
Post by: Woofy613 on September 14, 2008, 09:17:12 PM
I wish to do the following, which I am writing in pseudo code. 

What I wish to be able to do is to run a program, reading from sequential data files [name%1].  I wish to increment the calculation until the last data file [name%3] is reached. I also will be calling other batch flies to rename or copy the original output.
The range of %1 can be from 1 to 200 [or larger]

I am a newbie, so please excuse me...

The command line is:
batchfile %1 %2 %3

The batch file is:

:start
if %1 is greater than %3 goto end
program1 %1 %2
call prog1 %1 %2
call prog2 %1 %2

increment %1 by one
go to start

:end
exit

Title: Re: DOS Batch File - Incrementing in Loops
Post by: devcom on September 15, 2008, 06:57:25 AM
Code: [Select]
set var=%1

:LOOP
if '%1' gtr '%3' goto :EOF
program1 %var% %2
call prog1 %var% %2
call prog2 %var% %2

set /a var+=1
goto LOOP
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Woofy613 on September 15, 2008, 10:40:41 PM
Thanks.

Some problems:

1] I get a syntax error in this line: if '%1' gtr '%3' goto :EOF
2] var never increments

Advice please.

Thanks again.
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Dias de verano on September 16, 2008, 12:14:01 AM
@echo off
set /a var=%1
:LOOP
if %var% gtr %3 goto :END
program1 %var% %2
call prog1 %var% %2
call prog2 %var% %2
set /a var+=1
goto LOOP

:END
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Woofy613 on September 16, 2008, 06:33:03 AM
Thanks.

I have the same problems, even with the edits suggested.


1] No matter how I try to edit this line, I get syntax errors
if %var% gtr %3 goto :END

2] var never increments

Thanks again.
 
Title: Re: DOS Batch File - Incrementing in Loops
Post by: devcom on September 16, 2008, 06:47:14 AM
are you know how to use %1 %2 and %3 ??
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Dias de verano on September 16, 2008, 10:14:10 AM
are you know how to use %1 %2 and %3 ??

That is what I am wondering. There is a strong smell of homework around this thread.
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Jacob on September 16, 2008, 10:49:40 AM
are you know how to use %1 %2 and %3 ??

That is what I am wondering. There is a strong smell of homework around this thread.

dun dun dun.
 ;)
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Woofy613 on September 16, 2008, 05:45:15 PM
OS Win2000 SP4

The file is test.bat

command line: test 1 3

file:

echo on
set /a var=%1
:LOOP
IF  %var% GTR %2 GOTO :end
echo that's it
set /a var+=1
goto loop
:end
echo end it
exit

error message

IF  GTR 3 GOTO :end

syntax error.

Where have I made my mistake??
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Woofy613 on September 16, 2008, 08:49:26 PM
One correction:

My OS is DOS 7.1, the last pure DOS from Microsoft.  It is the one that comes with Windows 98.  My machine runs ONLY this DOS.  There is no Windows on the box.
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Dias de verano on September 17, 2008, 12:01:53 AM
You don't get set /a with genuine MS-DOS. Only NT4 and later members of NT family. That's why you're getting the error.
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Woofy613 on September 17, 2008, 07:49:30 AM
Thank you.

Is there anything I can do to make it work, possibly different code in the batch file?
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Dias de verano on September 17, 2008, 11:06:40 AM
Time to start learning QBasic.
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Woofy613 on September 17, 2008, 01:21:31 PM
Thank you for all your excellent help.

I would not like to be forced to learn another language now.  I have 100 massive data files to analyze and I would like to be able to loop thru them w/o having to baby sit the computer.

Is there any work around?  I would assume that people programming in pure DOS have had this problem and found a solution.

Thanks again.
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Dias de verano on September 17, 2008, 01:27:52 PM
In general, people have moved on from "programming in pure DOS" as you call it. When it was the only game in town, many people did learn QBasic, for precisely the reasons you are finding.
Title: Re: DOS Batch File - Incrementing in Loops
Post by: Woofy613 on September 17, 2008, 05:41:50 PM
Dias -

Thank you.  I appreciate your comment.  However ....

Eventually my programs will be ported to UNIX and I need to be able to develop them in DOS so that I can port. Qbasic is a Microsoft Language, that does not exist in UNIX.

If I could rely on your expertise, to "think outside of the box", it would be appreciated.  In other words, lets see if we can think in an innovative way to solve this.

Does anybody else on this forum have any ideas??

Thanks again.
Title: Re: DOS Batch File - Incrementing in Loops
Post by: thenomad on October 07, 2008, 09:28:59 PM
if this is going to be proted to unix, why not transfer the files into unix environment and make use of unix utilities like integer arithmetic at the ksh prompt. What you are trying to do seems to be impossible in the pure dos environment unless you can find a dos command line calculator to give you increments.

qbasic, along with being from microsoft, is pretty benign language and very easy to comprehend. I believe there are even some free basic interpreters which can use the qbasic code with little to no modification. so learning it would not be so bad of an idea. If you have the basic understanding of programming languages, you are more than half way thru anyways.

good luck