Microsoft KB Archive/43252

= Must DECLARE a FUNCTION Invoked from an External Library =

Article ID: 43252

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b

-



This article was previously published under Q43252



SUMMARY
To use a FUNCTION that is in a library (.LIB) or Quick Library (.QLB), you must have a DECLARE statement at the top of each module that uses the FUNCTION. This is documented in the &quot;Microsoft QuickBasic 4.0: Basic Language Reference&quot; manual for Versions 4.00 and 4.00b, Page 139, and the QuickBasic 4.50 on-line QB Advisor by choosing   DECLARE Statement (Basic Procedures)  and in the &quot;Microsoft Basic 7.0: Programmer's Guide&quot; on Page 53.

The documentation states that you must use DECLARE if you invoke a FUNCTION that is defined in another module. Library files (.LIB and .QLB) are &quot;other modules,&quot; as are SUBprogram or FUNCTION modules that start from a separate .BAS or MS-DOS file.

This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50 for MS-DOS, to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2, and to Microsoft Basic PDS Version 7.00 for MS-DOS and MS OS/2.



MORE INFORMATION
There are two reasons that DECLAREs are necessary for FUNCTIONs and not for SUBprograms.


 * 1) The only way to identify a SUBprogram without a DECLARE is with a CALL. You cannot use CALL with a FUNCTION because a FUNCTION returns a value and must be used in an assignment statement.
 * 2) Without the DECLARE, the compiler cannot know if you are referring to a variable, array, or FUNCTION.

Consider the following Basic statements: 'Is this a FUNCTION call or assignment of a variable? VAR1# = Func1# ' Is this a FUNCTION call or is this assigning ' an array element to a variable? VAR1# = Func1#(VAR2,VAR3) The DECLARE FUNCTION Func1# statement tells the compiler that you are using a FUNCTION when you use the name Func1# and that this is not a variable or an array.

Additional query words: QuickBas BasicCom

Keywords: KB43252

-

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

© Microsoft Corporation. All rights reserved.