I'm running a while loop and after about 3000 iterations get this error:
"Out of stack space"
Any idea why this happens/ how to fix it?
Thanks
I'm running a while loop and after about 3000 iterations get this error:
"Out of stack space"
Any idea why this happens/ how to fix it?
Thanks
The stack is where recursive routines store their active variables when recursed, and each recursion pushes another set of data (stack gets deeper) until things unwind and get taken off.
You have finite space on the stack; if rountines nest too deeply, you run out.
It's what happens if you stack work in an inbox as received and work only on the top item. If you get too far behind, the stack falls over.
The way to fix it is to redesign your code.
Use the collection object and push things to the collection object or to a hash table.
OK, thank you.
I have a master macro that runs a loop of 8,000 iterations or so.
Within the loop, if condition 1 is met, function 1 runs (function 1 is written in another module, outside of master), then returns back to master macro; if condition 2 is met, function 2 runs (function 2 is written in another module, outside of master), then returns back to master macro;
Every time I run this, I get "Out of stack space error" after about 2000 iterations.
If I put the code for function 1 and 2 within the code of master, and run the master, no error pops up. My prefference is to have master and functions 1 and 2 separate.
I'm a bit new to programming - what is the language I need to use to elliminate this error?
Thanks.
Post your code, remember to use Code tags
Hope that helps.
RoyUK
--------
For Excel Tips & Solutions, free examples and tutorials why not check out my web site
Free DataBaseForm example
Here it is:
Master Macro:
![]()
Please Login or Register to view this content.
Functions 1 and 2:
![]()
Please Login or Register to view this content.
Any luck with this?
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.
Threads merged. luv2glyd, please don't do that.
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.
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:
![]()
Please Login or Register to view this content.
Declare & Type all variables
Use Call vs. app/run
Ben Van Johnson
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks