Microsoft KB Archive/40635

= &quot;Permission Denied&quot; 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 &quot;Permission denied,&quot; error number 70.

Normally, you only get a &quot;Bad record number&quot; error message when attempting to access record number zero. However, the message &quot;Bad record number&quot; 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 &quot;Microsoft QuickBasic 4.0: Basic Language Reference&quot; manual for QuickBasic Versions 4.00 and 4.00b
 * 2) Page 259 of the &quot;Microsoft Basic Compiler 6.0: Basic Language Reference&quot; manual for Microsoft Basic Compiler Versions 6.00 and 6.00b
 * 3) Page 220 of the &quot;Microsoft QuickBasic 4.5: Basic Language Reference&quot; manual for QuickBasic Version 4.50
 * 4) Page 200 of the &quot;Microsoft Basic 7.0: Language Reference&quot; 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 &quot;LOCK... UNLOCK Statement Details&quot; in both Help systems.

The program example below demonstrates that a &quot;Permission Denied&quot; 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 &quot;test5&quot; FOR BINARY AS #1  'Open the same file as #1 and #2. OPEN &quot;test5&quot; FOR BINARY AS #2

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

OPEN &quot;test3&quot; FOR INPUT AS #5  'Open as #5 and #6. OPEN &quot;test3&quot; FOR INPUT AS #6

OPEN &quot;test3&quot; 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

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.