File sharing problems

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.

Cheers

Mat
pinmj001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

inthedarkCommented:
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
0
ampapaCommented:
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?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.