Difference between revisions of "Microsoft KB Archive/43252"

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - "<" to "<")
Line 49: Line 49:
 
== SUMMARY ==
 
== 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 &lt;Help&gt; &lt;Index&gt; DECLARE Statement (Basic Procedures) &lt;Details&gt; and in the &quot;Microsoft Basic 7.0: Programmer's Guide&quot; on Page 53.<br />
+
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 <Help&gt; <Index&gt; DECLARE Statement (Basic Procedures) <Details&gt; and in the &quot;Microsoft Basic 7.0: Programmer's Guide&quot; on Page 53.<br />
 
<br />
 
<br />
 
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.<br />
 
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.<br />
Line 73: Line 73:
 
   VAR1# = Func1#(VAR2,VAR3)
 
   VAR1# = Func1#(VAR2,VAR3)
 
                 </pre>
 
                 </pre>
The DECLARE FUNCTION Func1#(&lt;variables&gt;) 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.
+
The DECLARE FUNCTION Func1#(<variables&gt;) 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.
  
 
</div>
 
</div>

Revision as of 09:25, 21 July 2020

Knowledge Base


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 "Microsoft QuickBasic 4.0: Basic Language Reference" manual for Versions 4.00 and 4.00b, Page 139, and the QuickBasic 4.50 on-line QB Advisor by choosing <Help> <Index> DECLARE Statement (Basic Procedures) <Details> and in the "Microsoft Basic 7.0: Programmer's Guide" 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 "other modules," 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#(<variables>) 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