Microsoft KB Archive/129940

= PRB: Out of Stack Space Error Caused by Property Procedure =

Article ID: 129940

Article Last Modified on 12/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q129940



SYMPTOMS
Using a non-reserved Visual Basic keyword within a Property Procedure of the same name creates a recursive call to that Property statement resulting in this error:

Out of Stack Space Error.



CAUSE
Visual Basic allows you to define Properties and Methods that have the same name as non-reserved keywords because many keywords (such as Left) in previous versions of Visual Basic are used frequently by OLE servers. If you take advantage of this in your own Class, an "Out of Stack Space error" can occur in a Property Get Procedure when both of the following conditions are met:


 * A call to the non-reserved keyword with the same name as the Property is located within a Property Get Procedure.
 * The Property Get Procedure returns a Variant or Object.



RESOLUTION
Typically, if one of the following conditions is true, Visual Basic can determine whether to call the Property Get procedure or the non-reserved keyword:


 * The Property Get procedure doesn't return a Variant or Object. -or-


 * The call to the non-reserved keyword takes a different number of parameters then the Property Get procedure takes.

For example, given the following Property Get Property procedure, the Visual Basic Left function would be called instead of the Property Get procedure: Property Get Left as String Left = Left("Hello World",10) ' Visual Basic Left function called End Property Because the Property Get Procedure expects 0 parameters and the Visual Basic function expects 2, the Visual Basic Left function is called.

If, however, the Property Get Procedure returns either a Variant or an Object, the Property Get Procedure is called, regardless of the number of Parameters the Property Procedure expects. This occurs because Objects, which are now supported in Variants, can have a default property, which can take parameters themselves. When you call a function that returns a Variant or Object, and you pass the incorrect number of parameters, Visual Basic realizes that you intended to pass the parameters to the default property of the Object, so it generates a call to the default property with those parameters. In this case, the "Incorrect Number of Parameters" message is not generated because it is not necessarily known how many parameters are expected by the default property.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Start a new project in Visual Basic. Form1 is created by default. Add a Command Button (Command1) to Form1.  Add the following code to the Command1_Click procedure: Sub Command1_Click Dim clsClass1 As New Class1 MsgBox clsClass1.Left End Sub  Insert a Class Module (Class1) by choosing Class Module from the Insert Menu (ALT, I, C).  Add the following code to the Class1 module: Property Get Left ' This returns a Variant by default Const cTempStr = "Summer" Left = Left(cTempStr, 3) End Property </li> Press the F5 key to run the program.</li> Click the Command1 button. An 'Out of Stack Space' Error message appears at this point, where you might expect to see a Message Box with the phrase "Sum."</li></ol>

Additional query words: 4.00 vb4win vb4all

Keywords: kbprb KB129940

-

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

© Microsoft Corporation. All rights reserved.