Microsoft KB Archive/31939

= I/O to a File OPENed as &quot;NUL&quot; or &quot;NUL.xxx&quot; Does Nothing =

Article ID: 31939

Article Last Modified on 11/21/2006

-

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 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft GW-BASIC Interpreter 1.0

-



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 &quot;NUL&quot; or &quot;NUL.xxx&quot; (where &quot;xxx&quot; 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 &quot;File Not Found&quot; 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 &quot;NUL.DAT&quot;, 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 &quot;NUL.xxx&quot; ' or &quot;NUL&quot;, then &quot;the very first recor&quot; and &quot;the second record is&quot; will ' display on the screen: CLS OPEN &quot;NUL.DAT&quot; FOR RANDOM AS #1 FIELD #1, 20 AS Var1$ LSET Var1$ = &quot;the very first recor&quot; PUT #1, 1 LSET Var1$ = &quot;the second record is&quot; PUT #1, 2 GET #1, 1 PRINT Var1$ GET #1, 2 PRINT Var1$ The following program, which inputs from a sequential access file called &quot;NUL&quot;, properly gives an &quot;Input Past End&quot; error at run time: OPEN &quot;NUL&quot; FOR INPUT AS #1 INPUT #1, x PRINT x CLOSE

Additional query words: QuickBas BasicCom

Keywords: KB31939

-

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

© Microsoft Corporation. All rights reserved.