LOCK |
LOCK([#] filenumber [,recordrange]) |
Locks access to parts of a file for other processes. |
filenumber | The number of the file (Integer). |
recordrange | (Optional) Refers to a range of records (or bytes) that are to be locked. |
REMARKS |
* Prevents another process from accessing all or part of the open file that corresponds to the filenumber argument. * You can use the UNLOCK statement to control access to a file. * The equivalent .NET function is [[Microsoft.VisualBasic.FileSystem.Lock]] * For the Microsoft documentation refer to learn.microsoft.com |
Sub Testing()
Dim MyRecord As udtRecord
Dim RecordNumber As Integer
'Open "C:\Temp\MyText.txt" For Output As #1 'Close #1 '
'Open "C:\Temp\MyText.txt" For Binary As #1 'RecordNumber = 1 'MyRecord.ID = "001"
'MyRecord.Name = "Name1"
'Put #1, , MyRecord
'MyRecord.ID = "002"
'MyRecord.Name = "Name2"
'Put #1, , MyRecord
'Close #1
Open "C:\Temp\MyText.txt" For Binary Shared As #1 Len = Len(MyRecord)
RecordNumber = 1 ' Define record number.
Lock #1, RecordNumber ' Lock record.
Get #1, RecordNumber, MyRecord ' Read record.
MyRecord.ID = 111 ' Modify record.
MyRecord.Name = "New Name1"
Put #1, RecordNumber, MyRecord ' Write modified record.
Unlock #1, RecordNumber ' Unlock current record.
Close #1 ' Close file.
End Sub
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top