Likely cause of "Out of stack space" in VB6

12,024

Solution 1

Your error is described over here in MSDN.

Note: This MSDN article is related to Visual Studio 2005. But it's likely to say that the same limits are for VB6.

  • Check that procedures are not nested too deeply.
  • Make sure recursive procedures terminate properly.
  • If local variables require more local variable space than is available, try declaring some variables at the module level. You can also declare all variables in the procedure static by preceding the Property, Sub, or Function keyword with Static. Or you can use the Static statement to declare individual static variables within procedures.
  • Redefine some of your fixed-length strings as variable-length strings, as fixed-length strings use more stack space than variable-length strings. You can also define the string at module level where it requires no stack space.
  • Check the number of nested DoEvents function calls, by using the Calls dialog box to view which procedures are active on the stack.
  • Make sure you did not cause an "event cascade" by triggering an event that calls an event procedure already on the stack. An event cascade is similar to an unterminated recursive procedure call, but it is less obvious, since the call is made by Visual Basic rather than an explicit call in the code. Use the Calls dialog box to view which procedures are active on the stack.

[update]

You can find the Visual Studio 6 (VB6) article over here.

  • You have too many active Function, Sub, or Property procedure calls. Check that procedures aren't nested too deeply. This is especially true with recursive procedures, that is, procedures that call themselves. Make sure recursive procedures terminate properly. Use the Calls dialog box to view which procedures are active (on the stack).
  • Your local variables require more local variable space than is available. Try declaring some variables at the module level instead. You can also declare all variables in the procedure static by preceding the Property, Sub, or Function keyword with Static. Or you can use the Static statement to declare individual Static variables within procedures.
  • You have too many fixed-length strings. Fixed-length strings in a procedure are more quickly accessed, but use more stack space than variable-length strings, because the string data itself is placed on the stack. Try redefining some of your fixed-length strings as variable-length strings. When you declare variable-length strings in a procedure, only the string descriptor (not the data itself) is placed on the stack. You can also define the string at module level where it requires no stack space. Variables declared at module level are Public by default, so the string is visible to all procedures in the module.
  • You have too many nested DoEvents function calls. Use the Calls dialog box to view which procedures are active on the stack.
  • Your code triggered an event cascade. An event cascade is caused by triggering an event that calls an event procedure that's already on the stack. An event cascade is similar to an unterminated recursive procedure call, but it's less obvious, since the call is made by Visual Basic rather than by an explicit call in your code. Use the Calls dialog box to view which procedures are active (on the stack).

Solution 2

I had a case where instead of:

Public Property Let EmployeeNo(ByVal vdata As String)
    mvarEmployeeNo = vdata
End Property

I have by mistake:

Public Property Let EmployeeNo(ByVal vdata As String)
    EmployeeNo = vdata
End Property
Share:
12,024
CJ7
Author by

CJ7

Updated on June 08, 2022

Comments

  • CJ7
    CJ7 almost 2 years

    Is the most likely cause of an Error 28 - "Out of stack space" error an infinite or very deep recursion that is using up too much stack memory?

    What are the other likely causes?