I/O to a File OPENed as "NUL" or "NUL.xxx" Does Nothing (31939)



The information in this article applies to:

  • Microsoft QuickBASIC 1.0
  • Microsoft QuickBASIC 1.01
  • Microsoft QuickBASIC 1.02
  • Microsoft QuickBASIC 2.0
  • Microsoft QuickBASIC 2.01
  • Microsoft QuickBASIC 3.0
  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft GW-Basic Interpreter

This article was previously published under Q31939

SUMMARY

Basic will allow input from or output to the DOS null device, which is a file named "NUL" or "NUL.xxx" (where "xxx" can be any set of none, one, two, or three alphanumeric letters). The DOS null device is always empty when you input from it and is never created on disk when you write to it.

This information applies to the following products:

  1. Microsoft QuickBasic Compiler Versions 1.00, 1.01, 1.02, 2.00, 2.01, 3.00, 4.00, 4.00b and 4.50 for the IBM PC
  2. Microsoft Basic Compiler Version 6.00 for MS-DOS and MS OS/2
  3. Microsoft Basic PDS Version 7.00 for MS-DOS and OS/2
  4. Microsoft GW-Basic Interpreter Version 3.20

MORE INFORMATION

The DOS command TYPE NUL will display nothing. The DOS command DIR NUL will give a "File Not Found" error. The DOS command COPY EXISTING.FIL NUL, which copies an existing file to the NUL device, will do nothing.

The following program writes to and reads from a file called "NUL.DAT", which has been opened with random access. The file is never created on the disk, and nothing is retrieved from the file or printed on the screen:
' If you modify the OPEN statement to open a filename other than "NUL.xxx"
' or "NUL", then "the very first recor" and "the second record is" will
' display on the screen:
CLS
OPEN "NUL.DAT" FOR RANDOM AS #1
FIELD #1, 20 AS Var1$
LSET Var1$ = "the very first recor"
PUT #1, 1
LSET Var1$ = "the second record is"
PUT #1, 2
GET #1, 1
PRINT Var1$
GET #1, 2
PRINT Var1$
				
The following program, which inputs from a sequential access file called "NUL", properly gives an "Input Past End" error at run time:
OPEN "NUL" FOR INPUT AS #1
INPUT #1, x
PRINT x
CLOSE
				

Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB31939