+ Reply to Thread
Results 1 to 12 of 12

Out of stack space error

Hybrid View

  1. #1
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679
    Any luck with this?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    Sorry but that code appears to be all over the place.

    You seem to be running subs from other subs then calling back to those subs again.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Threads merged. luv2glyd, please don't do that.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Routine A calls B and C
    Routine B calls A
    Routine C calls A
    So the stack gets deeper until it overflows.

    I don't think anyone could help without having a clue as to what you're trying to do, and seeing the six missing routines.

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,927
    1. You have not declared and typed your variables, so VB is assigning them the default type of Variant (16 bytes vs 2 for Integer and 4 for Long)
    2. The variable intrade is used in each of the three procedures and it appears that you intended to have the value accessed and changed by each of the three variables; but, since it is undeclared, each procedure initializes a local variable of 16 byte Variant-type with no link to any previous value each time the procedure is called. You should declare it as Public at the top of the module (outside any procedure) and type it as Integer.
    3. You are using "application.run..." to run code in each module, instead, use CALL procedure name.
    4. In your sub procedures, you are trying to exit the procedure and return to the main procedure by using the App...run.. language; however, this will only call the main as a subroutine of the calling subroutine and start it from the beginning of the code. Since main is calling each of the subs, you have an untended infinite loop that crashes Excel. If you had CALLed the sub from the main, the End Sub would exit the sub and return to the main at the next line after the CALL line:

    Public intrade as Integer
    sub main()
        ....
        do some stuff
        ....
        call function_one
        return here from function one and do more stuff
        call function_two
        return here from function two, etc
    end sub
    
    sub function_one()
        do something
    end sub
    sub function_two()
    ...
    end sub

    Declare & Type all variables
    Use Call vs. app/run
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1