Skip to Content
VB & VBA in a Nutshell: The Language
book

VB & VBA in a Nutshell: The Language

by Paul Lomax
October 1998
Intermediate to advanced
656 pages
16h 10m
English
O'Reilly Media, Inc.
Content preview from VB & VBA in a Nutshell: The Language
Unlock Statement

Syntax

Unlock [#]filenumber[, recordrange]

filenumber

Use: Required

Data Type: Integer

Any valid file number.

recordrange

Use: Optional

Data Type: Long

A range of records.

The syntax for the recordrange argument is:

recnumber | [start] To end

recnumber

Use: Required

Data Type: Long

The record or byte number to unlock.

start

Use: Optional

Data Type: Long

The first record or byte number to unlock.

end

Use: Required

Data Type: Long

The last record or byte number to unlock.

Description

Use the Unlock statement in situations where more than one part of your program may need read and write access to the same data file. The Unlock statement removes a lock placed on a section or the whole file that was locked with the Lock statement.

Rules at a Glance

  • Records and bytes in a file are always numbered sequentially from 1 onwards.

  • To unlock a particular record, specify its record number and only that record is unlocked.

  • Use the Unlock statement omitting recnumber to unlock the whole file.

  • The Unlock statement unlocks an entire file opened in input or output (sequential) mode, regardless of the recordrangeargument.

  • If you omit the start argument in the recnumber syntax, Unlock unlocks all records from the start of the file to record or byte number end.

Programming Tips and Gotchas

  • You must take care to remove all file locks using the Unlock statement before either closing a file or ending the application; otherwise, you can leave the file in an unstable state. This, of course, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Absolute Beginner's Guide to VBA

Absolute Beginner's Guide to VBA

Paul McFedries
Visual Basic 2015 Unleashed

Visual Basic 2015 Unleashed

Alessandro Del Sole

Publisher Resources

ISBN: 1565923588Catalog PageErrata