Microsoft KB Archive/92724
Article ID: 92724
Article Last Modified on 8/16/2005
- Microsoft Visual Basic for MS-DOS
- Microsoft BASIC Professional Development System 7.0
- Microsoft BASIC Professional Development System 7.1
- Microsoft QuickBasic 4.5 for MS-DOS
This article was previously published under Q92724
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.
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.
The following program demonstrates this problem. To re-create the problem you will have to do the following:
- Create a file called INFILE.DAT with a line of text in it. For example:
This is a sentence in INFILE.DAT.
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
- 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