Solved

Run time error "28"  Out of stack space

Posted on 1998-02-04
3
234 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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