11-10-2004, 06:13 AM
How can qbasic write to a certain line of a file that already has text in it, without using the command APPEND to add on to the end of the file, or use the command OUTPUT to overwrite the file entirely? Thanks!
Quote:How can qbasic write to a certain line of a file that already has text in it, without using the command APPEND to add on to the end of the file, or use the command OUTPUT to overwrite the file entirely? Thanks!If you don't have experience with Random or Binary files, and you're not ready to learn now, then you're going to have to:
Quote:How can qbasic write to a certain line of a file that already has text in it, without using the command APPEND to add on to the end of the file, or use the command OUTPUT to overwrite the file entirely? Thanks!
INPUT "which line do you want to replace? choose a number from 1 to 5"; A
'which line of the 5 lines do you want to change? maybe line 4?
'These are the lines in the text file. Create a text file
'and make 5 lines like so: then name it whatever.txt
'12
'23
'45
'56
'98
INPUT "what number do you want to replace it with"; B
'now choose what number you want to have replace what's printed
'on that particular line you chose.
DIM C(1 TO 5)
OPEN "whatever.txt" FOR INPUT AS #1
'C(1 to 5) contains the numbers in the text file
FOR D = 1 TO 5
INPUT #1, C(D)
E = E + 1 'E increases 1 each time through the loop.
IF E = A THEN 'If E equals the line number you chose.....
C(D) = B 'C(D) changes to the value you chose.
END IF
NEXT D
CLOSE #1
OPEN "whatever.txt" FOR OUTPUT AS #1
'now everything is printed out to the same text file.
FOR D = 1 TO 5
PRINT #1, C(D)
NEXT D
CLOSE #1
Quote:Thanks guys! I'll check this stuff out..
Actually, what I really wanted to do was just take all the lines in one file, assemble them into one line
Quote:Thanks guys! I'll check this stuff out..Your original request and what you "really want" are totally different. Thanks for sending us on a wild goose chase. :wink:
Actually, what I really wanted to do was just take all the lines in one file, assemble them into one line