error 28: out of stack space call function

I

ina

Hello guys,

I am newbie in VBA and I have an error 28: out of stack space; I do not
understand why :(

Sub test1()

Dim cenom, cenonlala As String

cenom = test2(cenonlala) ' I get this string name to input in my
query

End Sub


Function test2(cenomtras As String) As String 'this function give me a
string name

cenonlala = "LALA"

test2 = test2("LALA")

End Function


Can someone help me?

Ina
 
G

Guest

Right here, you call test2 from within test2

Function test2(cenomtras As String) As String 'this function give me a
string name

cenonlala = "LALA"

' recursive call here
test2 = test2("LALA")

End Function

Since you don't have any terminating logic in the Function, it continues to
call itself until it runs out of stack space.
 
D

Dana DeLouis

I am newbie in VBA and I have an error 28: out of stack space; I do not
understand why :(

Hi. Here's a technique to understand why.
Put your cursor somewhere within sub "test1" and hit the F8 key over and
over to follow the code.
This will step you thru your code. When you get to Test2, you will see that
the code calls Test2 over and over again. Vba eventually runs out of a
designated storage area (a 'stack' ) to keep track of each call.

I think in earlier versions the limit was about 2000+ calls, but in Excel
2003, it looks like it was increased to about 5000+ calls.

This is just a wild guess at your code...

Sub Test3()
Dim cenom As String
cenom = Test4
End Sub


Function Test4()
Const cenonlala As String = "LALA"
Test4 = cenonlala
End Function
 
T

Tim Williams

test2 calls itself in an endless loop: that is probably not what you meant to do.

What should your code be doing?
 
G

Guest

Just assign the value to return to the name of the function:

Sub test1()

Dim cenom, cenonlala As String

cenom = test2(cenonlala)
End Sub


Function test2(cenomtras As String) As String

cenonlala = "LALA"

test2 = cenonlala

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top