Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Run time error "28"  Out of stack space

Posted on 1998-02-04
3
Medium Priority
?
262 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

916 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