I'm working with plain text files that I need to read a bunch of stuff out of, and write some other stuff back in. In order to refresh my memory about how such things work, I threw together a lil sample proggy just doing the basics (as one does). Trouble is, it's got me a lil flummoxed.
It's supposed to just (essentially) create and write to a file (using WriteFile and WriteLine), close the file, then reopen it using OpenFile and WriteLine to it some more. At this stage, I'm not concerned whether it overwrites stuff, or needs to be the same length, or anything like that... but at the moment, it just seems to ignore me.
What obvious and n00b-esque thing am I missing?
(bear in mind I'm only interested in working with complete lines - the sort of thing ReadLine and WriteLine do - so I don't expect anything like any of the other reads and writes (for ints, bytes etc) are likely relevant)
It's supposed to just (essentially) create and write to a file (using WriteFile and WriteLine), close the file, then reopen it using OpenFile and WriteLine to it some more. At this stage, I'm not concerned whether it overwrites stuff, or needs to be the same length, or anything like that... but at the moment, it just seems to ignore me.
What obvious and n00b-esque thing am I missing?
(bear in mind I'm only interested in working with complete lines - the sort of thing ReadLine and WriteLine do - so I don't expect anything like any of the other reads and writes (for ints, bytes etc) are likely relevant)
Const testFileName$ = "testfile.txt" Global numLines, textLine$, i, temp$ Global filehandle filehandle = WriteFile (testFileName$) If Not filehandle Then RuntimeError "File could not be created" Restore startData Read numLines For i = 1 To numLines Read textLine$ WriteLine filehandle, textLine$ Next ; i CloseFile filehandle filehandle = OpenFile (testFileName$) If Not filehandle Then RuntimeError "File could not be opened" For i = 1 To 3 temp$ = ReadLine$ (filehandle) ; read through a couple of lines temp$ = ReadLine$ (filehandle) ; just to move through the file a bit Next ;------------------------------------------------------------------------- ; This line doesn't seem to do anything. This is what I'm asking about. WriteLine filehandle, "This is the line that gets added later. Or not." ;------------------------------------------------------------------------- CloseFile filehandle End .startData Data 6 Data "This is a test to see what things do. This is line one." Data "This is line two." Data "This is line three. A few more to come." Data "This is line four." Data "This is line five - the penultimate line." Data "This is line six. The end."