Microsoft KB Archive/42664

= QB.EXE Confusing If TYPE Statement Used in SUB/FUNCTION =

Article ID: 42664

Article Last Modified on 11/21/2006



This article was previously published under Q42664



SUMMARY
TYPE definitions must all be contained in the module level code, and are not allowed within SUB...END SUB or FUNCTION...END FUNCTION blocks.

However, the QB.EXE environment of QuickBasic Versions 4.00, 4.00b, and 4.50 can give confusing error messages if a TYPE definition is entered into a SUBprogram or FUNCTION, making it seem as if TYPE definitions are allowed in SUBprograms and FUNCTIONS.

This problem occurs only when using QB.EXE. If you compile your program with BC.EXE and a TYPE definition exists within a SUBprogram or FUNCTION, the following appropriate (and unconfusing) error message displays:

&quot;TYPE statement improperly nested

Skipping forward to END TYPE statement&quot;

Within the QBX.EXE environment supplied with Microsoft Basic PDS Version 7.00, the following correct error message is generated when you attempt to put a TYPE declaration in a SUBprogram:

&quot;Illegal in SUB, FUNCTION, and DEF FN&quot;



MORE INFORMATION
The following sequence of events demonstrates the problem:

  The following program is entered: TYPE typeA a AS INTEGER END TYPE END

SUB suba TYPE typeA b AS INTEGER END TYPE DIM c AS typeB  Attempting to run the above program generates the following error message, pointing to the TYPE statement in &quot;subA&quot;:

&quot;Duplicate Definition&quot;

 Changing &quot;TYPE typeA&quot; to &quot;TYPE typeB&quot; in &quot;subA&quot; and then running the program generates the following error message, pointing to the DIM statement in &quot;subA&quot;:

&quot;TYPE not Defined&quot;

 Changing the DIM statement in &quot;subA&quot; to &quot;DIM c AS typeA&quot; and then running the program, then generates the following expected error message:

&quot;Illegal in Procedure or DEF FN&quot;



If a TYPE statement is encountered in a SUB or FUNCTION, it should be flagged as an error prior to flagging errors related to the TYPE statement that are past the TYPE statement.

Additional query words: QuickBas

Keywords: KB42664

-

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

© Microsoft Corporation. All rights reserved.