Microsoft KB Archive/40635

From BetaArchive Wiki
Knowledge Base


"Permission Denied" Is Only Error for Basic Record/File LOCK

Article ID: 40635

Article Last Modified on 11/21/2006



APPLIES TO

  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS
  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 6.0b
  • Microsoft BASIC Professional Development System 7.0



This article was previously published under Q40635

SUMMARY

The only error message that you will get for locked files or records is "Permission denied," error number 70.

Normally, you only get a "Bad record number" error message when attempting to access record number zero. However, the message "Bad record number" has nothing to do with the LOCK statement, contrary to a statement in the documentation (listed below).

MORE INFORMATION

This documentation error occurs in the following places. Each of these references is in the language reference manual for that product and is under the entry describing the LOCK... UNLOCK statement.

  1. Page 259 of the "Microsoft QuickBasic 4.0: Basic Language Reference" manual for QuickBasic Versions 4.00 and 4.00b
  2. Page 259 of the "Microsoft Basic Compiler 6.0: Basic Language Reference" manual for Microsoft Basic Compiler Versions 6.00 and 6.00b
  3. Page 220 of the "Microsoft QuickBasic 4.5: Basic Language Reference" manual for QuickBasic Version 4.50
  4. Page 200 of the "Microsoft Basic 7.0: Language Reference" manual for Microsoft Basic PDS Version 7.00

Each of the references above makes the following misleading statement:

If you attempt to access a file that is locked, the following error messages may appear:

Bad record number
Permission denied

This same incorrect information appears in the QB Advisor online Help system for QuickBasic Version 4.50 and in the Microsoft Advisor online Help system for QBX.EXE, which comes with Microsoft Basic PDS Version 7.00. The error occurs under the entry for the "LOCK... UNLOCK Statement Details" in both Help systems.

The program example below demonstrates that a "Permission Denied" error occurs if a program does any of the following:

  1. LOCKs a file that is already LOCKed.
  2. Reads any record from a random access file where the whole file is LOCKed.
  3. Reads any part of a sequential file where any part of that file is LOCKed.
  4. Reads the portion of a BINARY access file that was LOCKed.

The following is sample code:

OPEN "test5" FOR BINARY AS #1   'Open the same file as #1 and #2.
OPEN "test5" FOR BINARY AS #2

OPEN "test4" FOR RANDOM AS #3 LEN = 11   'Open as #3 and #4.
OPEN "test4" FOR RANDOM AS #4 LEN = 11

OPEN "test3" FOR INPUT AS #5   'Open as #5 and #6.
OPEN "test3" FOR INPUT AS #6

OPEN "test3" FOR INPUT AS #7   'Open the same file as #5 and #6.

FIELD #3, 11 AS f3$
FIELD #4, 11 AS f4$

LOCK #1, 30 TO 32       'Lock some bytes in #1.
LOCK #3                 'lock entire file #3
LOCK #5, 1              'Lock first record in #5.
CLS
n = 10
LOCK #7          'Permission denied attempt to lock a locked file
a$ = INPUT$(34, #2) 'Permission denied if any part is locked.
GET #4, n           'Permission denied for any n except n=0
                    'n=0 gives a bad file number
INPUT #6, a$        'Permission denied for record 1
UNLOCK #1, 30 TO 32
UNLOCK #3
UNLOCK #5, 1
CLOSE
                


Additional query words: QuickBas BasicCom

Keywords: KB40635