File sharing problems

Posted on 2004-10-22
Last Modified: 2010-05-02
Hi there,

I have two applications:

First one is written by someone else and writes to several log files, some it appends to and some it over writes. I dont know the fequency in which it writes to these, but i would say fair oftem maybe every second.

Second one is written by me and what i want to do is read these files every minutes. I am having problems where when I have one of the files open the first application reports that there is a sharing violation and that it cannot write to the file.

What i would like to know is: is there a way for me to open these files in VB without causing the other application to error and say there is a sharing violation. i have tried a couple of methods, including using the filecopy method, but have not had any luck. If anyone has any ideas that would be great.


Question by:pinmj001
    LVL 17

    Assisted Solution

    Point 1

    If you want to open a file and let another app write to the file then you need to open like this for sequenatial read operations:

    lfn = FreeFile
    Open "C:\MyFolder\MyFile.log" For Input Shared As lfn

    Or like this for more flexible binary (read from any point any amount) operations):

    lfn = FreeFile
    Open "C:\MyFolder\MyFile.log" For Binary Access Read Shared As lfn

    Point 2

    However, you still have a problem because the software in the other app may not have included the "Share" attribute when they are appending, writing or reading from a file.  In which case you need to ask the chap to correct his code.

    For example, many people thinK that this is how you open and read a file:

    lfn = FreeFile
    Open "C:\MyFolder\MyFile.log" For Input As lfn ' shoddy code asking for trouble
    LVL 8

    Accepted Solution

    pinmj001, you might try creating a copy of the file and then reading your information from the copy and then delete the copy avoiding the file share issue altogether?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: MongoDB Object-Document Mapper for NodeJS

    NodeJS (JavaScript on the server) is awesome, but some developers get confused about NoSQL when it comes to working in Node with MongoDB (NoSQL database). Do you need a better explanation of how to use Node.js with MongoDB? The most popular choice is the Mongoose library.

    Introduction This article makes the case for using two modules in your VBA/VB6 applications to provide both case-sensitive and case-insensitive text comparison operations.  Recently, I solved an EE question using the LIKE function.  In order for th…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    845 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now