Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am attempting to read multiple variables from a text file to a batch file. I need the batch to read two variables per line 1, then run code, then loop and read next two variables on line 2, line 3, etc... repeat until eof
Any help would be great.
Thanks

would that be microsoft quick basic? different versions of basic may have different string processing ability but an approach like this:
OPEN datafile$ FOR INPUT AS #1
OPEN batchfile$ FOR OUPUT AS #2DO WHILE NOT EOF(1)
LINE INPUT #1, a$
var1$ = MID$(a$, leftvarstart, LEN(leftvar))
var2$ = MID$(a$, rightvarstart, LEN(rightvar))
PRINT #2, "batch commands " + var1$ + " " + var2$
LOOP
CLOSE #1, #2now don't just copy and paste that in but work out some of lower case words programmatically... for example:
datafile$ might be "C:\BATCH.DAT"
and
batchfile$ might be "C:\COMMANDS.BAT"
or you could assign those values with datafile$ = "witchever file", or have the program get them by prompting for user input, or from the command line using the basic key word COMMAND$var1$ and var2$ are ok as they are and represent the variables you want to read and write.
lelftvarstart$ and rightvarstart$.... you determine the structure of your datafile to know these values. if you intend to use the batch file for processing files, you might have a datafile like:
C:\SOME_ANNOYING_SOUND.WAV C:\GAMEOVER.MP3
C:\BANG.WAV C:\SHOTGUN.MP3
etc......... etc........if that is case consider making the file TAB delimited or you may need another string process routine... for example:
LINE INPUT #1, a$
leftvarstart = 1
FOR X = TO LEN(a$)
IF MID$(a$, X, 1) = " " THEN
rightvarstart = X + 1
EXIT FOR
END IF
var1$ = MID$(a$, leftvarstart, LEN(leftvar))
var2$ = MID$(a$, rightvarstart, LE (rightvar))
next you just want to write to the output file your DOS commands ("batch commands ") whatever they are, followed by your 2 variables for each line which will be the args for the DOS commands so don't forget the blank space... (+ " ")

![]() |
floppy disk(s) fail (co)
|
Thanks Ronin & Tech G...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |