|
-
Mar 30th, 2006, 10:17 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Flush data in output file
I have to write logging information into a file:
VB Code:
Open "C:\pgm.log" For Output As #1
...
print#1, "debug data"
...
close #1
Is there a way to force VB to flush the buffer to the disk once in a while? I could not find any flush function for files. Right now I have to close and re-open the file with append after every write, which is much too slow.
-
Mar 30th, 2006, 03:08 PM
#2
Re: Flush data in output file
If you want your program to up date automatically then you can stick your print code in a timer.
VB Code:
Private Sub Timer1_Timer()
Dim handle As Integer
handle = FreeFile
Open "C:\Documents and Settings\Carl\My Documents\Programming\List1.txt" For Append As handle
'//.....
Print #handle, "Data Log 1"
'//.....
Close #handle
End Sub
My Timers interval is set to 1000 (1 second) so my file will update every second. I hope this helps you.
Jenova
-
Mar 31st, 2006, 09:03 AM
#3
Thread Starter
Hyperactive Member
Re: Flush data in output file
The problem is that I could attempt to log something in the file while the timer closed the file to re-open it with append.
Still I think closing/appending to a file is a crapy way of forcing the buffers to flush to the disk. I wish that was a better way.
-
Mar 31st, 2006, 09:38 AM
#4
Re: Flush data in output file
 Originally Posted by JacquesLebrun
The problem is that I could attempt to log something in the file while the timer closed the file to re-open it with append.
Still I think closing/appending to a file is a crapy way of forcing the buffers to flush to the disk. I wish that was a better way.
You don't have to open and close it for every write.
Open it in your Form Load event.
Put the code to write to it in the timer event.
Close the file in your Form Unload event.
-
May 9th, 2006, 03:21 AM
#5
Re: Flush data in output file
Hi,
I'm looking for the same thing. 
I know if can be done with API calls, but then you need to write to the file via api calls too :/
If I find it I'll post up here.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
May 9th, 2006, 03:31 AM
#6
Re: Flush data in output file
 Originally Posted by JacquesLebrun
Still I think closing/appending to a file is a crapy way of forcing the buffers to flush to the disk. I wish that was a better way.
Very true But I think that's the only way to do it. What I do is set up a counter variable and after every x number of writes I close & re-open the file. Cumbersome & ugly, but it works.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|