This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!
Lock, Unlock Statements Example
This example illustrates the use of the
Lock and
Unlock statements. While a record is being modified, access by other processes to the record is denied. This example assumes that
TESTFILE
is a file containing five records of the user-defined type
Record
.
Type Record ' Define user-defined type.
ID As Integer
Name As String * 20
End Type
Dim MyRecord As Record, RecordNumber ' Declare variables.
' Open sample file for random access.
Open "TESTFILE" For Random Shared As #1 Len = Len(MyRecord)
RecordNumber = 4 ' Define record number.
Lock #
1,
RecordNumber ' Lock record.
Get #1, RecordNumber, MyRecord ' Read record.
MyRecord.ID = 234 ' Modify record.
MyRecord.Name = "John Smith"
Put #1, RecordNumber, MyRecord ' Write modified record.
Unlock #
1,
RecordNumber ' Unlock current record.
Close #1 ' Close file.