Siebel VB Language Reference > Siebel VB Language Reference >

Lock Statement


This standard VB statement controls access to an open file.

Syntax

Lock [#]filenumber[, [start] [To end]]

Argument
Description
filenumber
The file number of the open file as used in the Open statement
start
A long integer representing the number of the first record or byte offset to lock or unlock
end
A long integer representing the number of the last record or byte offset to lock or unlock

Returns

Not applicable

Usage

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 parameters. Locks on open files must be removed before closing the file, or unpredictable results may occur.

Example

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.

(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

See Also

Open Statement
Unlock Statement


 Siebel VB Language Reference
 Published: 18 June 2003