QBasic 1.1: LOCK Statement
Explanation
LOCK, UNLOCK Statements
LOCK limits or prevents access to a file by a network process.
UNLOCK releases the locks imposed by the last LOCK statement.
Worth knowing
Useful and cross-version information about the programming environments of QBasic, QuickBasic and Visual Basic for DOS.
Syntax
LOCK [#]filenumber% [,{record& | [start&] TO end&}] |
UNLOCK [#]filenumber% [,{record& | [start&] TO end&}] |
Description / Parameter(s)
filenumber% |
The number of an open file. |
record& |
For random-access files, the number of a record to lock, relative to the first record in the file. For binary files, the number of a byte to lock, relative to the first byte in the file. |
start& and end& |
The numbers of the first and last records or bytes in a range of records or bytes to lock or unlock. |
For sequential files, LOCK and UNLOCK affect the entire file. |
Example
'This example runs only in a network environment.
OPEN "TEST.DAT" FOR RANDOM AS #1
FOR i% = 1 TO 10
PUT #1, , i%
NEXT i%
LOCK #1, 2 'Lock record 2.
GET #1, 2, i%
UNLOCK #1, 2 'Unlock record 2.