What is the test for whether a file is open?
"I don't want to burden the caller
with opening the file in the event he never has to write to it."
What does anything you do "burden" the user, why would he ever/never want to
write to it.
Determining if a text-file is open, while possible, is not always
straightforward. It depends which app has opened the file. Typically with
most text editors, even if the file is open you can 'Output' or 'Append' the
file. Notepad will not update though some others will refresh with latest
contents when reactivated. However if the file is open in say Word the code
will fail with permission denied, so you can trap for that.
In passing, wouldn't you normally want to Append the log rather than rewrite
it entirely each time.
Regards,
Peter T
"Jim Luedke" wrote in message
...
What's the test for whether a file is currently open (or closed)?
My app writes to a log file, but I don't want to burden the caller
with opening the file in the event he never has to write to it. So I
want:
Dim H As Long
Sub Log(Msg as String)
If Not IsOpen(H) then
Open LogFile For Output As #H
Print #H, FileHeader & DateTime
Print #H,
End If
Print #H, Msg
End Sub
Sub Main
Repeat
If Not Something Then
Log "Oops"
End If
Until SomethingElse
Close #H
End Sub
So what expression should "IsOpen(H)" be?
Thanks.
***
|