QBasic Multiple files appending

Status
Not open for further replies.

cryptid

Journeyman
Well i have to edit multiple files situated in diffrent locations in the computer i know it can be done using the command [open "C:\file.txt" for append as #1] but my problem is that i have to append the same lines in the other files also so is there a way that i can append the same lines at a time to all the files [i am a lazy person i dont like to type much & any way i need my program to be small and fast] so is there a way to open multiple files and append all of the at once i tried doing thins but it didnt work

open "C:\file.txt" for append as #1
open "D:\file123.txt" for append as #1
Print #1, "hi Blha Blha BLHA"
close #1

but the compiler returned some error
 

sakumar79

Technomancer
try putting the writing-to-file code within a subroutine, then use open .... for append as #1 and then gosub command...

The Below text is Pseudo code - I have forgotten 75% BASIC commands.

OPEN file1 for append as #1
gosub writeSub

OPEN file2 for append as #1
gosub writeSub

...

and then

writeSUB
{
Print #1, "xyz"
}


Arun
 
OP
C

cryptid

Journeyman
sakumar79 said:
try putting the writing-to-file code within a subroutine, then use open .... for append as #1 and then gosub command...

The Below text is Pseudo code - I have forgotten 75% BASIC commands.

OPEN file1 for append as #1
gosub writeSub

OPEN file2 for append as #1
gosub writeSub

...

and then

writeSUB
{
Print #1, "xyz"
}


Arun

I tried doing this

OPEN "C:\WINDOWS\txt1.txt" FOR APPEND AS #1
GOSUB writeSub
OPEN "C:\Windows\txt2.txt" FOR APPEND AS #1
GOSUB writeSub
writeSub
{
PRINT #1, "Hi"
}

and the compiler gave a error sayin that "expected:statement" at the first Flower Bracket "{" what do i do now
 
OP
C

cryptid

Journeyman
alright i got the solutoin to my previous problem now i got another problem after u open the first file and use the Gosub command it will write to the first file file and then it will skip the second file and continue with the codes after the writeSub what do i do to append to the seonf file also i tried using the goto command but then it will keep looping and flood the seconf file with "Hi" statement so please tell me what to do
 

sakumar79

Technomancer
forgot to close the file havent we? can be a part of the gosub (at the end) or of the main program (before the open file command for the second file)

Arun
 
Status
Not open for further replies.
Top Bottom