Solved

Run time error "28"  Out of stack space

Posted on 1998-02-04
3
226 Views
Last Modified: 2008-03-03
I am getting a Run time error in the following program.  What I'm trying to accomplish is display a message box asking the user if they want to play again.  If the answer is Yes, clear the form, pick another spot, and start over again.  Here it is...


Option Explicit
Dim intMagicX As Integer
Dim intMagicY As Integer

Private Sub GetSpot()
 Randomize
 intMagicX = Rnd(1) * Me.ScaleWidth
 intMagicY = Rnd(1) * Me.ScaleHeight
End Sub

Private Function CalcDistance(X As Single, Y As Single) As Single
 CalcDistance = (Sqr(Abs(X - intMagicX)) ^ 2) + _
 (Sqr(Abs(Y - intMagicY)) ^ 2)
End Function

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim sngDistance As Single
Dim square As Integer
sngDistance = CalcDistance(X, Y)
Me.CurrentX = X
Me.CurrentY = Y

If sngDistance = 0 Then
 Me.Print "Magic"
 msgBox
Else
 Me.Print Format$(sngDistance, "#.#0")
End If
End Sub

Public Function msgBox()

Dim Message As String
Dim Response As Integer

' The Message of the dialog box.
Message = "Do you want to play again?"
Response = msgBox(Message)
If Response = vbYes Then
 Refresh
GetSpot
End If
End Function

Thanks!!
0
Comment
Question by:Millos
3 Comments
 
LVL 3

Accepted Solution

by:
rmichels earned 0 total points
ID: 1455611
You are recursivelly calling a function, with no end.  So the stack just keeps growing:

Public Function msgBox()

              Dim Message As String
              Dim Response As Integer

              ' The Message of the dialog box.
              Message = "Do you want to play again?"
              Response = msgBox(Message)

In the above code you call msgBox in side of msgBox.. which creates and infinite call chain (well not really infinite since you will run out of stack space).  If you are trying to call the VB message box function within your function, then rename your function msgBox to something else.
0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1455612
If you want to call the VB messagebox function you can use Messagebox API or type

vba.msgbox

you do not need to rename the function......  this answer is better
0
 

Author Comment

by:Millos
ID: 1455613
Thanks RMichaels.  It solved the problem.


0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now