Lock Procedure


Lock Procedure

Class

Microsoft.VisualBasic.FileSystem

Syntax

     Lock(fileNumber[, record]) 

or:

     Lock(fileNumber[, fromRecord, toRecord]) 


fileNumber (required; Integer)

Any valid file number of a file opened with FileOpen


record (optional; Long)

The 1-based record or byte number at which to commence the lock


fromRecord (optional; Long)

The first 1-based record or byte number to lock


toRecord (optional; Long)

The last 1-based record or byte number to lock

Description

The Lock procedure prevents another process from accessing a record, section, or whole file until it is unlocked by the Unlock procedure. Use the Lock procedure in situations where multiple programs or more than one instance of your program may need read-and-write access to the same data file.

Usage at a Glance

  • If only the fileNumber argument is included, the entire file is locked.

  • record is interpreted as a record number in Random files and as a byte number in Binary files.

  • The Lock procedure locks an entire file opened in Input or Output (sequential) mode, regardless of any record number arguments.

  • Attempting to access a locked file or portion of a file generates a "Permission denied" error.

  • The matching Unlock procedure must include the same arguments.

  • You must take care to remove all file locks with the Unlock procedure before either closing a file or ending the application; otherwise, you can leave the file in an unstable state. Where appropriate, error-handling code must correctly unlock any locks that are no longer necessary.

Version Differences

  • In VB 6, the fromRecord argument can be left blank to lock all records up to toRecord. This syntax is not supported in .NET.

  • In the VB 6 Lock statement, you can separate the fromRecord and toRecord arguments with the To keyword. In the .NET Lock procedure, this syntax is not supported.

  • In Visual Basic 2005, the My.Computer.FileSystem object provides more robust access to file-management features.

See Also

Unlock Procedure




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net