The information in this article applies to:
SUMMARYWith two sequential files open, #1 for INPUT and #2 for OUTPUT, the following statement incorrectly sends output to the screen instead of to file #2:
This behavior occurs in the Standard and Professional Editions of
Microsoft Visual Basic for MS-DOS, version 1.0; in Microsoft QuickBasic
for MS-DOS, versions 4.0, 4.0b, and 4.5; in Microsoft Basic Compiler
for MS-DOS and MS OS/2, versions 6.0 and 6.0b; and in Microsoft Basic
Professional Development System (PDS) for MS-DOS and MS OS/2,
versions 7.0 and 7.1. This limitation is documented in the README.DOC
file for Microsoft Basic PDS for MS-DOS and MS OS/2, versions 7.0 and
7.1.
This information is also included with the Help file provided with the Standard and Professional Editions of Microsoft Visual Basic for MS-DOS, version 1.0. To work around this behavior, put the INPUT$ function into a temporary string variable, then PRINT that temporary string into the second file. The general rule to observe is as follows: do not nest input/output (i/o) statements or functions within other i/o statements or functions. This is a design limitation. MORE INFORMATIONThe above limitation is related to the following restriction mentioned on Page 149 of the "Microsoft Visual Basic version 1.0 for MS-DOS Language Reference": "Avoid using I/O statements in a FUNCTION procedure called from an I/O statement; they can cause unpredictable results."It is also related to the following restriction mentioned on Page 146 of the "Microsoft Basic 7.0: Language Reference" for versions 7.0 and 7.1: "Avoid using I/O statements in a FUNCTION procedure called from an I/O statement; they can cause unpredictable results." See also Page 201 of "Microsoft QuickBasic 4.0: Language Reference" for versions 4.0 and 4.0b for the same caveat. The following code example shows the unexpected behavior:
The input file TEST1.DAT is as follows:
123456789012345The following program shows how to work around this problem by using a temporary string variable to accept the input before writing to file #2. This program correctly writes to file #2, not the screen:
Microsoft QuickBasic for MS-DOS, version 3.0 successfully writes to
file #2, not the screen. Microsoft GW-Basic for MS-DOS, version 3.22
also writes to file #2, not the screen (when you put line numbers in
the source file).
Additional query words: VBmsdos QuickBas BasicCom 1.00 4.00 4.00b 4.50 6.00 6.00b 7.00 7.10
Keywords : |
Last Reviewed: December 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |