bas7advr.hlp (Topic list)
LOCK...UNLOCK Statement Details
  Syntax  Details  Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
The LOCK...UNLOCK statement controls access by other processes to all
or part of an opened file.
 
LOCK [#]filenumber% [,{record& |[start&] TO end&}]
    .
    .
    .
UNLOCK [#]filenumber% [,{record& | [start&] TO end&}]
    ■ The argument record& can be any number from 1 to 2,147,483,647
      (equivalent to 2^31 - 1). A record can be up to 32,767 bytes long.
    ■ 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&.
 
Important
    ■ 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.
    ■ Do not use LOCK and UNLOCK on devices or ISAM tables.
    ■ If you attempt to access a file that is locked, BASIC may generate
      the following error messages:
 
        "Bad record number"
        "Permission denied"
 
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.
    ■ 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.
    ■ LOCK and UNLOCK execute only at run time if you are using OS/2 or
      versions of DOS that support networking (version 3.1 or later). In
      DOS, you must run the 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.