Open/writing files on a network? 
Author Message
 Open/writing files on a network?

        Okay, I have this problem.  My program has to log usage, and the program
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.
        I think I can do something by catching errors, but I'm not sure.  In an
ideal situation, the program would try to open the file, and if it can't (it's
being used), then try again, and again, until it succeeds.  Can anyone lend a hand?

        Email responses are preferred since I can't always sort through all the
messages posted here.

                Thanks,

                Jeff

--
Jeffrey Gunn                    | Technical Assistant or something...

        ----                    | University of New Hampshire  
"Saying Windows 95 is equal to Macintosh is like finding a potato
  that looks like Jesus and believing you've witnessed the second coming."
                                -Guy Kawasaki



Wed, 28 Jul 1999 03:00:00 GMT  
 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/



Sun, 01 Aug 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Open a text file, search for place holder, then write data to file

2. Writing configuration file for network app

3. Writing to file on a network

4. Writing to file on a network

5. Write method is too slow for writing to a network drive

6. Open network file from database

7. Open a network access file

8. Opening Files on Harddrive/Network

9. How to open files for read/write in .aspx

10. Opening File for Write

11. open a binary file for reading/writing

12. Opening / Writing To Files In PDS 7.1

 

 
Powered by phpBB® Forum Software