No EOF (CTRL+Z) Marker Written at End of Sequential File (25996)



The information in this article applies to:

  • 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 Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1

This article was previously published under Q25996

SUMMARY

Programs compiled in the following Basic products don't add an end-of-file (EOF) marker [chr$(26), or CTRL+Z, or also known as ASCII byte value 26] at the end of output or appended sequential files:

Microsoft QuickBasic version 4.0, 4.0b, and 4.5 for MS-DOS; Microsoft Basic Professional Development System (PDS) versions 7.0 and 7.1 for MS-DOS and OS/2; and Microsoft Basic Compiler versions 6.0 and 6.0b for MS-DOS and OS/2.

Sequential files created by programs compiled with QuickBasic versions 4.0 and later, Basic Compiler 6.0 and later, and Basic PDS 7.0 and later will correctly read into programs compiled in QuickBasic version 3.0 even though there is no EOF marker, but other non-Basic DOS applications (those that follow the DOS versions 1.x standard for EOF) may generate an "input past end" error looking for the CTRL+Z.

This is not an error in the QuickBasic or compiled Basic software.

MORE INFORMATION

The lack of writing CTRL+Z to mark the end of the file was a deliberate change to allow QuickBasic programs to read files that contain embedded CTRL+Zs. CTRL+Zs can often occur within binary files and screen files saved with the BSAVE command.

The use of CTRL+Z to mark the end of file is a DOS versions 1.x application standard (which was carried over from the CP/M-80 operating system). Applications written for DOS versions 2.x and 3.x standards use the exact number of bytes in the file to determine the end of file, which is a more practical design. This file size is stored for each file in the file allocation table (FAT) on each disk.

You can write your own CTRL+Z to the end of a file by writing a program that opens the file for append and sends a chr$(26) to the file, for example:
   OPEN "filename" FOR APPEND AS #1
   PRINT #1,CHR$(26);   'Must use ";" to prevent writing extra CR+LF
   CLOSE #1
				
Note that no version of Basic automatically appends CTRL+Z to the end of files opened for RANDOM or BINARY access.

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB25996