Output Misdirected Using PRINT # and Function with OPEN

ID: Q92724


The information in this article applies to:
  • Microsoft Visual Basic Standard and Professional Editions for MS-DOS, version 1.0
  • Microsoft BASIC Professional Development System (PDS) for MS-DOS, versions 7.0, 7.1
  • Microsoft QuickBASIC for MS-DOS, version 4.5


SYMPTOMS

Calling a function that performs an OPEN statement from within a PRINT # statement incorrectly prints the information to the screen instead of to the file. This problem also occurs with the WRITE # statement.


STATUS

Microsoft has confirmed this to be a bug in the Standard and Professional Editions of Microsoft Visual Basic for MS-DOS, version 1.0; Microsoft Basic Professional Development System for MS-DOS, versions 7.0 and 7.1; and Microsoft QuickBasic for MS-DOS, version 4.5. We are researching this problem and will post new information here as it becomes available.

One possible workaround to this problem, is to uncomment the two lines in front of the PRINT # statement in the example below. These lines assign the string returned by the function to a temporary variable and then use the temporary variable in the PRINT statement. This avoids calling the function directly from the PRINT # statement and the program then acts as expected.


MORE INFORMATION

The following program demonstrates this problem. To re-create the problem you will have to do the following:

  1. Create a file called INFILE.DAT with a line of text in it. For example:
    This is a sentence in INFILE.DAT.


  2. Type in the following code:
    
    DECLARE FUNCTION retstring$ ()
    ' Open output file.
    OPEN "outfile.dat" FOR OUTPUT AS #1
    ' Call function and print to output file. The PRINT fails and
    ' prints to screen.
    ' Uncomment following lines to workaround the problem.
    ' temp$ = retstring$
    ' PRINT #1, temp$
    PRINT #1, retstring$
    END
    
    FUNCTION retstring$
      ' Open input file.
      OPEN "infile.dat" FOR INPUT AS #2
      ' Get string from input file.
      LINE INPUT #2, f$
      ' Close input file.
      CLOSE #2
      retstring$ = f$
    END FUNCTION 


  3. Run the program.


You will see that the information from your file is incorrectly printed to the screen instead of to the file.

Additional query words: VBmsdos QuickBas BasicCom 1.00 7.00 7.10 4.5 buglist1.00 buglist7.00 buglist7.10 buglist4.50

Keywords :
Version : MS-DOS:1.0,4.5; :7.0,7.1
Platform : MS-DOS
Issue type :


Last Reviewed: December 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.