Microsoft KB Archive/33301

= FUNCTION Procedures Cannot Be Invoked in I/O Statements =

Article ID: 33301

Article Last Modified on 11/21/2006



This article was previously published under Q33301



SUMMARY
You should avoid invoking (or nesting) a FUNCTION procedure in a Basic statement that performs output to a file. Instead, the returned value of the FUNCTION procedure should be assigned to an intermediate variable, and the intermediate variable can then be used in the I/O statement. (A FUNCTION procedure is defined in a FUNCTION...END FUNCTION block.)

This and other restrictions are described on Page 201 of the &quot;Microsoft QuickBasic 4.0: Basic Language Reference&quot; manual for versions 4.00 and 4.00b, as follows:

Because Basic may rearrange arithmetic expressions for greater efficiency, avoid using FUNCTION procedures that change program variables in arithmetic expressions. Also avoid using FUNCTION procedures that perform I/O in I/O statements. Using FUNCTION procedures that perform graphics operations in graphics statements may also cause side effects.

The same restriction is mentioned on Page 201 of the &quot;Microsoft Basic Compiler 6.0: Basic Language Reference&quot; for versions 6.00 and 6.00b for MS OS/2 and MS-DOS. It is also mentioned on Page 146 of the &quot;Microsoft Basic 7.0: Language Reference&quot; manual.

Please note that user-defined functions defined with the DEF FN statement do not have the above restrictions.

Additional query words: QuickBas BasicCom

Keywords: KB33301

-

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

© Microsoft Corporation. All rights reserved.