How to get around open files

I'm writing a simple chat-type program that works by reading a file on the network.  

All is fine except for sending a message when other users are "listening" or reading the files.  There is a delay in the listening and obviously "time holes" where data could be written.

However, I'm having difficulty getting this to work.

I've got properly written ErrorHandlers (they work the first time, then the second time they get through to the 'open "file.dat" for output access write as #1' statement they give a Run-time error 70 -- "Permission Denied")  

Am I missing something here?  I've tried Timers, and loops to "check" but the permission denied error still persists (even though there's an errorhandler!)

Does anyone have any ideas why?  and if so, some code to show me =P

Thanks a bunch,
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.

Only one error handler can be active at a time.  Make sure that once you have entered the error handler GoTo, you either call Resume Next, or Exit Sub.  If you encounter another error while still in the error handler, it will not be handled.  In other words, you cannot have nested error handlers.

Post a snippet of your error code.

This set of lines will keep trying until it's possible to open the file.

on error resume next
  open "c:\chat.txt" for output as 1
loop while err
on error goto 0

Ture Magnusson
Karlstad, Sweden
If you want to replace the file chat with a really small winsock chat program let me know, and I'll post the code....

this code could help:

dim file_no as integer
file_no = Freefile

open "file.dat" for output access write as #file_no

Actually what happens is that the OS allots a file no. to each open file. Now when the first file is being opened, it would get file no 1. The next time you say open #1, it tries to open an open file and fails.
Freefile gets around this problem by querying the OS for the next free file no.
But be careful, this could open too many instances of the same file if many clients are connected.

Good luck.
Check your options. You have 3 options for errorhandling. When it says 'Always Break on Errors', it does what it says. It always breaks when an error occurs. Even when you have errorhandlers

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
Programming Languages-Other

From novice to tech pro — start learning today.