Equinox Online Help - Language Reference - A to Z

Home

FileUnlock

Applies to
SyntaxFileUnlock HandleItem, StartExpression, LengthExpression
Action[Statement] Unlocks a specified number of bytes in a random file.
ScopeUsable anywhere
NotesThis statement allows you to unlock bytes in a file, preventing access by another user on a network. LengthExpression number of bytes are unlocked, starting at StartExpression. The first byte of the file is byte number 1. To unlock the entire file, supply StartExpression as 1 and LengthExpression as -1. To test if a section of the file is unlocked, attempt the read or write operation required and examine the error return. This statement will not work if the file has been opened as a sequential file. File sharing must be enabled in the operating system. The system workarea SysError is set to 2 if the unlock attempt fails, 1 if an error occurs, otherwise zero.
CategoryFile IO
See Also FileClose, FileCloseAll, FileDelimiters, FileInput, FileInputLine, FileLock, FileMovePosition, FileOpen, FilePosition, FilePrint, FileRead, FileReadLine, FileReadBinary, FileReadFile, FileUnlock, FileWrite, FileWriteBinary, FileWriteFile
Example

This method opens a file with sharing enabled, locks some bytes, reads them and then unlocks them.

string Buffer
handle hnd

| Open the file
FileOpen "MYDATA.DAT", RandomReadOnly + DenyNone, hnd

if hnd = -1 then
Alert "File Opening Error."
exit method
end if

| Lock the first 30 bytes
FileLock hnd, 1, 30

if syserror then
alert "File Locking Error."
exit method
end if

| Read the first 30 bytes into a string
FileReadString hnd, Buffer, 30

if syserror then
Alert "File Reading Error."
exit method
end if

| Unlock the first 30 bytes
FileUnlock hnd, 1, 30

if syserror then
Alert "File Unlocking Error."
exit method
end if

| . . and close the file

FileClose hnd