Can anyone tell me about the locks that I can put in files accessed using OPEN method? What is the difference between LOCK READ,LOCK WRITE,LOCK READ WRITE and SHARED?
Printable View
Can anyone tell me about the locks that I can put in files accessed using OPEN method? What is the difference between LOCK READ,LOCK WRITE,LOCK READ WRITE and SHARED?
Lock read = other processes (other programs) cannot read the file
Lock write = other cannot write to file (but can read it)
Shared= other can read or write the file
lock read Write = other cannot open the file for reading or for writing
Here a couple of example from MSDN
This code example opens the file in Binary mode for reading; other processes can't read file.
Open "TESTFILE" For Binary Access Read Lock Read As #1
This code example opens the file for sequential output; any process can read or write to file.
Open "TESTFILE" For Output Shared As #1
' Close before reopening in another mode.
Close #1
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater