Lock File Method
The Lock File method controls access to an open file. It does not return a value.
Format
Lock [#]filenumber[, [start] [To end]]
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
filenumber |
The file number that the Open statement uses to open the file. |
start |
A long integer that identifies the number of the first record or byte offset to lock or unlock. |
end |
A long integer that identifies the number of the last record or byte offset to lock or unlock. |
Specifying the Start Argument and End Argument
The Lock File method locks the file according to the following modes:
Binary mode. The start argument and the end argument identify byte offsets.
Random mode. The start argument and the end argument identify record numbers:
If you include the start but not the end, then it locks only the record or byte that the start argument identifies.
If you include the end but not the start, then it locks records or bytes from the record number or offset 1 to the end.
Input mode, output mode, or append mode. It locks the entire file. It ignores the start argument and the end argument.
Removing Locks
You must use the Lock File method and the Unlock File method in pairs to remove a lock, and the arguments that you use with these methods must be identical. For more information, see Unlock File Method.
You must configure Siebel VB to remove a lock on an open file before it closes the file. If you do not do this, then unpredictable results might occur.
Example
In the following example, if the file is already in use, then this code locks the file that other users on a network share. The CreateFile subroutine creates the file that the main subroutine uses:
(general) (declarations)
Option Explicit
Declare Sub CreateFile
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)
Next x
Close #1
End Sub
Sub Button_Click
Dim btngrp, icongrp
Dim defgrp
Dim answer
Dim noaccess as Integer
Dim msgabort
Dim msgstop as Integer
Dim acctname as String
noaccess = 70
msgstop = 16
Call CreateFile
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
Else
Lock #1
Line Input #1, acctname
Unlock #1
End If
Close #1
End If
Kill "C:\TEMP001"
End Sub