Trouble with eof...

BlitzMax Forums/BlitzMax Beginners Area/Trouble with eof...

Dubious Drewski(Posted 2005) [#1]
I'd like to append to a file.
Currently, I have a loop that tests eof.
When eof hits, I'm trying to Writeline some more data.
It finds eof, prints a debug notification that it's writing
to the file, but the file remains the same. What's going
on here?

Small example:
Repeat
Print "searching in file..."
Local line:String = ReadLine(file)

' if line$ has what I want, I exit this loop
' if I never find the thing I want, I'll append it to the file:

If Eof(file) Then
Print "found eof, writing more..."
WriteLine file, "yada"
EndIf
Forever


Dubious Drewski(Posted 2005) [#2]
...And how the heck do I make one of those nice, scrollable boxes in a post?


Scott Shaver(Posted 2005) [#3]
are you opening the stream as writable?

OpenStream:TStream( url:Object,readable=True,writeable=True )


Dubious Drewski(Posted 2005) [#4]
Actually I had not written in those flags, so it was working
with defaults. But even after I put them in, I get the same
result. Thanks though.


Dubious Drewski(Posted 2005) [#5]
So, to absolutely simplify the question, I should ask
"How do I write to the end of a file?"


tonyg(Posted 2005) [#6]
Local myfile:TStream = OpenStream("test.txt")
While Not Eof(myfile)
   Print ReadLine(myfile)
Wend
SeekStream(myfile, StreamSize(myfile))
WriteLine(myfile, "yada")
CloseStream(myfile)
FlushMem



Dubious Drewski(Posted 2005) [#7]
Thank you Tonyg. I never thought of using seekstream. I
can't make the proper changes in my code, so I'll start over
with yours and build up from there.

ps. How did you make that box? I want to know, damnit!


Kuron(Posted 2005) [#8]
Forum Codes:
http://www.blitzbasic.com/faq/faq_entry.php?id=2


Dubious Drewski(Posted 2005) [#9]
Ah, well that's very handy. Thank you. I suppose If I can't find it in a sticky, I won't find it.


Yan(Posted 2005) [#10]
Isn't this a bug?
You shouldn't need to seek to the end of the file as you're already there...
Local myfile:TStream = OpenStream("test.txt")
While Not Eof(myfile)
   Print ReadLine(myfile)
Wend
Print myfile.Pos()
SeekStream(myfile, StreamSize(myfile))
Print myfile.Pos()
WriteLine(myfile, "yada")
CloseStream(myfile)
FlushMem
end
...Or have I missed something?


Dubious Drewski(Posted 2005) [#11]
I would agree with you, but I don't know anything.


tonyg(Posted 2005) [#12]
EOF takes you to the end of the file. If you could add a newline command then you might be able to continue.
I just didn't know how to do that so gave the way I knew.