Microsoft KB Archive/57368

= Explanation of Critical Error Codes Returned by ERDEV =

Article ID: 57368

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic for MS-DOS
 * Microsoft GW-BASIC 3.2, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft GW-BASIC 3.22, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft GW-BASIC 3.23, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * 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
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q57368



SUMMARY
ERDEV is an integer function that returns an error code from the last device to declare a critical error. ERDEV is set by the critical error handler, Interrupt 24h, when MS-DOS detects a critical MS-DOS call error.

For block and character device errors, ERDEV will contain the error code from Interrupt 24h in the lower 8 bits. For block devices only, bit positions 9 to 16 contain device-attribute information which is found in the device-driver header of the device that the error is coming from.

ERDEV can also be set by a time-out error on the communications port and indicates which option in the OPEN COM statement (CD, CS, or DS) is experiencing the time-out.

When using Microsoft Basic PDS for MS-DOS, version 7.0 or 7.1, ERDEV can also be set by a time-out error on the communications port and indicates which option in the OPEN COM statement (CD, CS, or DS) is experiencing the time-out.

The information in this article is also included with the Help file provided with the Standard and Professional Editions of Microsoft Visual Basic for MS-DOS, version 1.0.



MORE INFORMATION
If ERDEV returns an error from a block device (such as a floppy disk drive or fixed disk) or from a character device (such as a terminal or printer), the low byte of ERDEV will return the MS-DOS error code, a value between 0 and 12. The following is a list of these errors:

0 write-protect error

1 unknown unit

2 drive not ready

3 unknown command

4 date error (CRC)

5 bad request structure length

6 seek error

7 unknown media type

8 sector not found

9 printer out of paper

10 write fault

11 read fault

12 general failure

13 reserved

14 reserved

15 invalid disk change (MS-DOS version 3.0 only)

For more information on MS-DOS error codes, see the section on Interrupt 24h on Page 481 of &quot;Advanced MS-DOS Programming, 2nd Edition,&quot; by Ray Duncan (Microsoft Press, 1988).

If the device returning an error is a block device, the high byte of the integer returned by ERDEV will contain device attribute information. This device attribute information comes from the device-attribute word in the device header. The only bits from this word returned by ERDEV are bits 15, 14, 13, XX, 3, 2, 1, and 0, in that order. XX indicates that bits 12 through 4 of the device-attribute word will always return zero. The following is a description of the bits in the device-attribute word that are meaningful to ERDEV:     Bit Position  Bit     Significance ---

8      15      0 if block device 7      14      1 if IOCTL read and write supported 6      13      1 if BIOS parameter block in boot sector should be used to determine media characteristics 0 if media ID byte should be used 4       3      1 if current CLOCK$ device 3       2      1 if current NUL device 2       1      1 if driver supports 32-bit sector addressing (MS-DOS version 4.0) 1       0      1 if current standard input device (stdin) For more information on device-attribute words, see Page 264 of the &quot;Advanced MS-DOS Programming&quot; Microsoft Press book.

ERDEV also returns information for COM time-out errors in the low byte. If there is a time-out, ERDEV is set to a value that indicates the signal line that timed out, according to the following table:   ERDEV Value    Signal Line ---   ---

128        Clear to Send (CTS) timeout 129        Data Set Ready (DSR) timeout 130        Data Carrier Detect (DCD) timeout The following program lines generate the MS-DOS and COM time-out error codes (low byte) and device attribute information (high byte): x= ERDEV DosErrCode = x AND &HFF           ' Low byte of ERDEV. DevAttr = (x AND &HFF00) \256     ' High byte of ERDEV. The following example prints the values of ERDEV after the program tries to OPEN a file on a floppy when the door is open:

Example
' Open floppy drive A: door open before running this example. ON ERROR GOTO ErrorHandler OPEN &quot;a:\file.dat&quot; FOR OUTPUT AS #1 END

ErrorHandler: PRINT &quot;ERDEV$='&quot;; ERDEV$; &quot;'&quot; PRINT &quot;ERDEV=&H&quot;; HEX$(ERDEV) DosErrCode% = ERDEV AND &HFF ' low byte of ERDEV.

RESUME NEXT

Additional query words: VBmsdos QuickBas BasicCom 1.00 3.20 3.22 3.23 2.00 3.00 4.00 4.00b 4.50 6.00 6.00b 7.00 7.10

Keywords: KB57368

-

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

© Microsoft Corporation. All rights reserved.