Unlock (statement)


Syntax

Unlock [#] filenumber [,{record | [start] To end}]

Description

Unlocks a section of the specified file, allowing other processes access to that section of the file.

Comments

The Unlock statement requires the following parameters:

 

Parameter

Description

 

filenumber

Integer used by the Basic Control Script to refer to the open file—the number passed to the Open statement.

 

record

Long specifying which record to unlock.

 

start

Long specifying the first record within a range to be unlocked.

 

end

Long specifying the last record within a range to be unlocked.

 

For sequential files, the record, start, and end parameters are ignored: the entire file is unlocked.

The section of the file is specified using one of the following:

 

Syntax

Description

 

No record specification

Unlock the entire file.

 

record

Unlock the specified record number (for Random files) or byte (for Binary files).

 

to end

Unlock from the beginning of the file to the specified record (for Random files) or byte (for Binary files).

 

start to end

Unlock the specified range of records (for Random files) or bytes (for Binary files).

 

The unlock range must be the same as that used by the Lock statement.

Example

This example creates a file named test.dat and fills it with ten string variable records. These are displayed in a dialog box. The file is then reopened for read/write, and each record is locked, modified, rewritten, and unlocked. The new records are then displayed in a dialog box.

Const crlf = Chr$(13) + Chr$(10)

Sub Main()
  a$ = "This is record number: "
  b$ = "0"
  rec$ = ""

  msg1 = ""
  Open "test.dat" For Random Access Write Shared As #1
  For x = 1 To 10
    rec$ = a$ & x
    Lock #1,x
    Put #1,,rec$
    Unlock #1,x
    msg1 = msg1 & rec$ & crlf
  Next x
  Close
  MsgBox "The records are: " & crlf & msg1

  msg1 = ""
  Open "test.dat" For Random Access Read Write Shared As #1
  For x = 1 to 10
    rec$ = Mid(rec$,1,23) & (11 - x)
    Lock #1,x          'Lock it for our use.
    Put #1,x,rec$      'Nobody's changed it.
    UnLock #1,x
    msg1 = msg1 & rec$ & crlf
  Next x
  MsgBox "The records are: " & crlf & msg1 
  Close

  Kill "test.dat"
End Sub

See Also

Lock (statement); Open (statement).

 

 

 

 

More information

U