KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q33301: FUNCTION Procedures Cannot Be Invoked in I/O Statements

Article: Q33301
Product(s): See article
Version(s): 4.00 4.00b 4.50
Operating System(s): MS-DOS
Keyword(s): ENDUSER | B_BasicCom | mspl13_basic
Last Modified: 9-JUL-1990

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
"Microsoft QuickBASIC 4.0: BASIC Language Reference" 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 "Microsoft BASIC
Compiler 6.0: BASIC Language Reference" for versions 6.00 and 6.00b
for MS OS/2 and MS-DOS. It is also mentioned on Page 146 of the
"Microsoft BASIC 7.0: Language Reference" manual.

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

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.