Solved

Run time error "28"  Out of stack space

Posted on 1998-02-04
3
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

732 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