Siebel VB Language Reference > VB Language Reference >
This standard VB statement controls access to an open file.
Lock [#]filenumber[, [start] [To end]]
The file number of the open file as used in the Open statement
A long integer representing the number of the first record or byte offset to lock or unlock
A long integer representing the number of the last record or byte offset to lock or unlock
For binary mode, start and end are byte offsets. For random mode, start and end are record numbers. If start is specified without end, then only the record or byte at start is locked. If end is specified without start, then records or bytes from record number or offset 1 to end are locked.
For Input, output, and append modes, start and end are ignored and the whole file is locked.
Lock and Unlock always occur in pairs with identical arguments. Locks on open files must be removed before closing the file, or unpredictable results may occur.
This example locks a file that is shared by others on a network, if the file is already in use. The second subprogram,
CreateFile, creates the file used by the main subprogram.
Declare Sub CreateFile
' Put the letters A-J into the file
Dim x as Integer
Open "c:\temp001" for Output as #1
For x = 1 to 10
Write #1, Chr(x + 64)
Dim btngrp, icongrp
Dim noaccess as Integer
Dim msgstop as Integer
Dim acctname as String
noaccess = 70
msgstop = 16
On Error Resume Next
btngrp = 1
icongrp = 64
defgrp = 0
answer = 1
If answer = 1 then
Open "c:\temp001" for Input as #1
If Err = noaccess then
'File Locked -Aborted
Line Input #1, acctname