qb45advr.hlp (
Topic list)
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
◄QuickSCREEN► ◄Details► ◄Example► ◄Contents► ◄Index►
──────────────────────────────────────────────────────────────────────────────
LOCK...UNLOCK Statement Details
Syntax
LOCK [#]filenumber [,{record |[start] TO end}]
[statements]
UNLOCK [#]filenumber [,{record | [start] TO end}]
These statements are used in networked environments where several
processes might need access to the same file.
Argument Description
filenumber The number with which the file was opened.
record The number of the record or byte to be locked; record
can be any number from 1 to 2,147,483,647 (equivalent
to 2^31 -1). A record may be up to 32,767 bytes in
length.
start The number of the first record or byte to be locked.
end The number of the last record or byte to be locked.
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, the arguments record, start, and end are the
number of a record relative to the beginning of the file. The first
record is record 1.
The LOCK and UNLOCK statements are always used in pairs. The arguments
to LOCK and UNLOCK must match exactly when you use them. See the second
example below.
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.
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. LOCK and UNLOCK only function at run time if you are
using versions of DOS that support networking (version 3.1 or later).
In addition, each terminal (or the network setup programs) must run
the DOS SHARE.EXE program to enable locking operations. Earlier
versions of DOS return an error message that reads "Advanced feature
unavailable if LOCK and UNLOCK are executed."
Note: 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. The arguments to LOCK
and UNLOCK must match exactly.
If you attempt to access a file that is locked, the following error
messages may appear:
"Bad record number"
"Permission denied"