Microsoft KB Archive/39380

= GET with BINARY File Fills String with NULL Bytes at EOF =

Article ID: 39380

Article Last Modified on 11/21/2006



This article was previously published under Q39380



SUMMARY
Using the GET #n statement with a file that has been opened for BINARY will fill the last bytes of an existing input string (which is the third parameter of GET) with NULLs. This only occurs if the length of the existing string exceeds the number of bytes between the file pointer (before the GET) and the end of file. This behavior applies to both fixed-length and variable-length string variables.

This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50, and to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2. (Earlier versions do not have a third parameter for the GET#n statement, and are not affected.)



MORE INFORMATION
The example program below demonstrates how this occurs. If TestString$ = &quot;123456789012345&quot; and TEST.DAT is a text file OPENed in BINARY containing only the string &quot;TEST&quot;, the following GET statement will alter TestString$ such that it contains the string &quot;TEST&quot; and 11 NULL bytes.

The following is a code example: CLS OPEN &quot;TEST.DAT&quot; FOR BINARY AS #1 TestString$ = &quot;123456789012345&quot; PRINT &quot;ASCII dump of string BEFORE GET from small file&quot; FOR i = 1 TO 15: PRINT ASC(MID$(TestString$, i, 1)); : NEXT i GET #1, 1, TestString$  ' This GET requires QuickBasic 4.x PRINT &quot;ASCII dump of string AFTER GET from small file&quot; FOR i = 1 TO 15: PRINT ASC(MID$(TestString$, i, 1)); : NEXT i END The output is as follows:

ASCII dump of string BEFORE GET from small file

49 50 51 52 53 54 55 56 57 48 49 50 51 52 53

ASCII dump of string AFTER GET from small file

84 69 83 84 0 0 0 0 0 0 0 0 0 0 0

Additional query words: QuickBas BasicCom

Keywords: KB39380

-

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

© Microsoft Corporation. All rights reserved.