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 Programming Example
◄QuickSCREEN► ◄Details► ◄Example► ◄Contents► ◄Index►
──────────────────────────────────────────────────────────────────────────────
LOCK...UNLOCK Statement Programming Examples
These example statements show how LOCK and UNLOCK are used in
networked environments, where several processes might need access
to the same file. These examples assume a random-access file.
----- Note -----
These examples are incomplete. Do not run them in their current form.
----------------
The following statement locks the entire file opened as number 2:
LOCK #2
The following statement locks only record 32 in file number 2:
LOCK #2, 32
The following statement locks records 1-32 in file number 2:
LOCK #2, TO 32
The two UNLOCK statements below unlock the records locked by
the preceding LOCK statements:
LOCK #1, 1 TO 4
LOCK #1, 5 TO 8
UNLOCK #1, 1 TO 4
UNLOCK #1, 5 TO 8
The following UNLOCK statement is illegal because the range in an
UNLOCK statement must exactly match the range in the corresponding
LOCK statements (no error is reported, but the statements produce
unpredictable results):
LOCK #1, 1 TO 4
LOCK #1, 5 TO 8
UNLOCK #1, 1 TO 8
The following program fragment opens a file and allows a user to lock
an individual record before updating the information in that record.
When the user is done, the program unlocks the locked record.
(Unlocking the locked records allows other processes to use the data
in the file.)
TYPE AccountRec
Payer AS STRING * 15
Address AS STRING * 20
Place AS STRING * 20
Owe AS SINGLE
END TYPE
DIM CustRec AS AccountRec
OPEN "MONITOR" SHARED AS #1 LEN = LEN(CustRec)
DO
CLS: LOCATE 10,10
INPUT "Customer Number? #"; Number%
' Lock the current record so another process
' doesn't change it while you're using it.
LOCK #1, Number%
GET #1, Number%
LOCATE 11,10: PRINT "Customer: ";CustRec.Payer
LOCATE 12,10: PRINT "Address: ";CustRec.Address
LOCATE 13,10: PRINT "Currently owes: $";CustRec.Owe
LOCATE 15,10: INPUT "Change (+ or -)", Change!
CustRec.Owe = CustRec.Owe + Change!
PUT #1, Number%
' Unlock the record.
UNLOCK #1, Number%
LOCATE 17,10: INPUT "Update another? ", Continue$
Update$ = UCASE$(LEFT$(Continue$,1))
LOOP WHILE Update$ = "Y"