Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating saving read/write txt files

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I've been working with qbasic for a while (nothing big) and I'm making a mud rpg. I was wondering how a person might create new *.txt files, reading them and writing to certan parts. Thanks.
 
Well you COULD just create your .txt file as a flat-text file and use the following code to read to a certain line

InFile = FREEFILE
OPEN "input.txt" FOR INPUT AS InFile

DO UNTIL LineCounter = 25
LINE INPUT #InFile, In$
LOOP

CLOSE #InFile


This will take you to line $25 and the text stored on that line will be stored in 'In$'

But if I were you, I would create the file as a fixed-length random file. This way you can read directly to a specific area. This makes it MUCh faster & efficient.


DIM ReadMe AS STRING * 25

InFile = FREEFILE
OPEN "input.txt" FOR RANDOM ACCESS READ WRITE SHARED AS InFile LEN = 25

GET #InFile, 25, ReadMe

Close #InFile


This will read position #25 in the file, and place it into the variable 'ReadMe' Thought for the day: Beware of Gods who cannot laugh...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top