Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Run time error "28"  Out of stack space

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

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

705 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