
Open/writing files on a network?
Quote:
>is run over a Novell network. When my program opens the log file to be written,
>I always have the possibility of colliding with another user on the network
>already writing to that file. I have written the code to open the file only
>when necessary, write real quick, and then close it again, but I really want to
>make it bulletproof.
You can use a counter with the error if the file is open
so like
Sub WriteToFile
Dim nFile%
nFile% = FreeFile
On Error Goto FileLocked
TryOpenFile:
Open [file] For Append Lock Read Write As #nFile
On error Goto 0
'do youre writing to the logfile here
Close #nFile
Exit Sub
FileLocked:
Sleep(1000) 'wait 1 second
nTryOpenFile = nTryOpenFile +1
If nTryOpenFile >10 Then Resume FileStillLocked
Resume TryOpenFile
FileStillLocked:
msgbox "can't open file.."
Exit Sub
End Sub
good luck
gr. walther
n.b. or try the SHARED parameter with the OPEN command
----- afknijpen -----
Walther Musch; Tilburg University
http://pi1438.kub.nl:2080/VisualBasicSource/