Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a call stack level limit?

I have a couple of colleagues looking at some bad code in Excel VBA, wondering is there a limit to the number of levels in a call stack

like image 844
Nick Avatar asked Oct 30 '25 03:10

Nick


1 Answers

Unless the function is tail-recursive and VBA can handle that (which it can't), you'll run into a stack overflow.

As a simple test I hacked together the following snippet:

Dim count As Integer

Sub Rec()
    count = count + 1
    Cells(1, 1) = count
    Call Rec
End Sub

which tells us that the limit for this is 4007 iterations, at least in my version of Excel 2007 here.

like image 86
Joey Avatar answered Oct 31 '25 17:10

Joey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!