Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
LOCK, UNLOCK Statement Details
◄Summary► ◄Details► ◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
LOCK [#]filenumber% [,{record& | [start&] TO end&}]
.
.
.
UNLOCK [#]filenumber% [,{record& | [start&] TO end&}]
Usage Notes
■ LOCK and UNLOCK statements are used in networked environments where
several processes might need access to the same file.
■ LOCK and UNLOCK statements are always used in pairs. The arguments
to LOCK and UNLOCK must match exactly.
■ Be sure to remove all locks with an UNLOCK statement before closing
a file or terminating your program. Failing to remove locks produces
unpredictable results.
■ Do not use LOCK and UNLOCK on devices or ISAM tables.
■ A record can be up to 32,767 bytes long.
■ If you specify just one record, then only that record is locked or
unlocked. If you specify a range of records and omit a starting record
(start&), then all records from the first record to the end of the range
(end&) are locked or unlocked. LOCK with no record arguments locks the
entire file, while UNLOCK with no record arguments unlocks the entire
file.
■ For binary-mode files, the arguments record&, start&, and end&
represent the number of a byte relative to the beginning of the file.
The first byte in a file is byte 1.
■ For random-access files, record&, start&, and end& are the number of a
record relative to the beginning of the file. The first record is
record 1.
■ If the file has been opened for sequential input or output, LOCK and
UNLOCK affect the entire file, regardless of the range specified by
start& and end&.
■ If you attempt to access a file that is locked, Visual Basic may
generate the error message, "Permission denied."
■ LOCK and UNLOCK execute only at run time if you are using a version of
MS-DOS that supports networking (version 3.1 or later). You must run the
SHARE.EXE program to enable locking operations.
■ MS-DOS version 3.0 or earlier returns an error message that reads,
"Advanced feature unavailable," if LOCK and UNLOCK are executed.