Writing To Text File: How To Flush The Buffer?

P

PeteCresswell

Got a routing that works, sort of.

I do a FreeFile, followed by Open For Append As... to get a pointer,
then I keep passing the same pointer to my little routine whenever I
want to write
another line to the text file.

Problem is that the lines I write are not appearing in the file
until sometime after I write them.

This becomes a problem if things go South after I've written but
before the file has been updated.

Is there some way to force a write when I do my Print
statement?

Or do I need to keep opening/closing the file every time I write?


Code:
------------------------------------------------------------------
Private Sub logFile_Write(ByVal theLine As String, ByVal
theFilePointer As Integer)
4000 DebugStackPush mModuleName & ":logFile_Write"
4001 On Error GoTo logFile_Write_err

' PURPOSE: To write a single line to the cash import log file.
' ACCEPTS: - Line tb written
' - Pointer to already-opened file

4002 Dim myLine As String

4010 myLine = Format$(Now(), "hh:nn:ss") & " " & theLine
4999 Print #theFilePointer, myLine

logFile_Write_xit:
DebugStackPop
On Error Resume Next
Exit Sub

logFile_Write_err:
BugAlert True, ""
Resume logFile_Write_xit
End Sub
------------------------------------------------------------------
 
P

PeteCresswell

... lines ... not appearing ... until sometime after I write them.

My suspicion is that the "Close" statement is what's currently taking
care of that.
 
A

aaron.kempf

dude, you're actually using Access to handle cash?

there is -NO- security available with jet, you do know that, right?

they removed security from access 2007 (format) because it was so easy
to crack

-aaron
 
P

PeteCresswell

Or do I need to keep opening/closing the file every time I write?

I wimped - took the easy path and just open/close the file for every
write.

Case Closed.
 
T

Tony Toews [MVP]

PeteCresswell said:
I wimped - took the easy path and just open/close the file for every
write.

I would usually recommend that every time anyhow. However be aware of the following
factor when it comes to .txt files.

The Haunted Door
http://thedailywtf.com/Articles/The-Haunted-Door.aspx

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
P

(PeteCresswell)

Per Tony Toews [MVP]:
I would usually recommend that every time anyhow. However be aware of the following
factor when it comes to .txt files.

The Haunted Door
http://thedailywtf.com/Articles/The-Haunted-Door.aspx

I can see it: Beeeeeeg log...... Beeeg problem....

Luckily for me at the moment:

- This is the log of a batch job run in the wee hours
(i.e. no practical time limit)

- Expected log size < 200 lines.


But it sure is something to keep in mind.

Sounds like my initial instinct to create the handle and then
just keep passing it around had some merit.
 
T

Tony Toews [MVP]

(PeteCresswell) said:
- This is the log of a batch job run in the wee hours
(i.e. no practical time limit)

- Expected log size < 200 lines.

Ah, then no problem.
But it sure is something to keep in mind.

Sounds like my initial instinct to create the handle and then
just keep passing it around had some merit.

I needed to do something similar a while back to figure out a failing API call. I
just called a subroutine passing some text. The sub did the open with append, wrote
the data and closed the txt file.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
A

aaron.kempf

Tony;

some of the shit that you admit to-- it's just insane

you're just a fucking idiot-- you've written ONE application and
you've attempted ONE upsizing.. and you think that you can run
around-- telling people to 'not use hungarian just because you're a
dipshit canuck who can't spell'

-Aaron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top