Home / Microsoft / Microsoft DOS / DOS Batch File - Incrementing in Loops
0 Members and 2 Guests are viewing this topic. « previous next »
Pages: 1 2 [All] - (Bottom) Print
Author Topic: DOS Batch File - Incrementing in Loops  (Read 19256 times)
Woofy613
Topic Starter
Greenhorn



Posts: 8


« 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

IP logged
devcom
Apprentice



Thanked: 37
Posts: 521


« Reply #1 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
IP logged

Download: Choice.exe
Woofy613
Topic Starter
Greenhorn



Posts: 8


« Reply #2 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.
IP logged
Dias de verano
Guest
« Reply #3 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
IP logged
Woofy613
Topic Starter
Greenhorn



Posts: 8


« Reply #4 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.
 
IP logged
devcom
Apprentice



Thanked: 37
Posts: 521


« Reply #5 on: September 16, 2008, 06:47:14 AM »

are you know how to use %1 %2 and %3 ??
IP logged

Download: Choice.exe
Dias de verano
Guest
« Reply #6 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.
IP logged
Jacob
Hopeful



Posts: 338


« Reply #7 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.
 ;)
IP logged

Woofy613
Topic Starter
Greenhorn



Posts: 8


« Reply #8 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??
IP logged
Woofy613
Topic Starter
Greenhorn



Posts: 8


« Reply #9 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.
IP logged
Dias de verano
Guest
« Reply #10 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.
IP logged
Woofy613
Topic Starter
Greenhorn



Posts: 8


« Reply #11 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?
IP logged
Dias de verano
Guest
« Reply #12 on: September 17, 2008, 11:06:40 AM »

Time to start learning QBasic.
IP logged
Woofy613
Topic Starter
Greenhorn



Posts: 8


« Reply #13 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.
IP logged
Dias de verano
Guest
« Reply #14 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.
IP logged
Woofy613
Topic Starter
Greenhorn



Posts: 8


« Reply #15 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.
IP logged
thenomad
Starter



Posts: 3


« Reply #16 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
IP logged
Pages: 1 2 [All] - (Top) Print 
Home / Microsoft / Microsoft DOS / DOS Batch File - Incrementing in Loops « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.105 seconds with 19 queries.