Run Time Error 28 - Out of Stack Space

BKrukowski

Board Regular
Joined
May 6, 2009
Messages
88
I as receiving a run time 28 error when I use a loop to fill a collection of class objects. The error occurs on line .Profit = ActiveCell.Offset(0, 3).value.
I have tried many references about this and they do not seem to apply to my code (I am not calling excessive Subs, I do not believe I have a recursive trigger (unless Setting class objects is a recursive trigger). When I look at the Stack only two things appear - the Sub I am running and something called [<non-basic Code="">]

Prior to the code below I a
assign variable to take the UserForm Controls values
Resize and Fill cells (with Selection.Interior)
Go to a different Sheet - this is a table of data that are attributes to the class object cReslEstate


Code:
Set GameRealEstate = New Collection
'Populate Real Estate randomly
i = 1
    
    For i = 1 To PropCount
    
       Set ReProp = New cRealEstate
       
        ActiveCell.Offset(Int(100 - 1 + 1) * Rnd + 1).Activate
        
        With ReProp
            .Name = ActiveCell.value
            .Cost = ActiveCell.Offset(0, 1).value
            .Rent = ActiveCell.Offset(0, 2).value
            .Profit = ActiveCell.Offset(0, 3).value
            .Mort = ActiveCell.Offset(0, 4).value
        End With
        
        
        Range("A:A").Find(GLoc).Activate 
        ActiveCell.Offset(0, 1).Activate
                
  Next I
</non-basic>
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I as receiving a run time 28 error when I use a loop to fill a collection of class objects. <non-basic code=""></non-basic>

Welcome to the Forum!

Can you post your code for the cRealEstate class? My guess is that you're triggering a recursive call in that code.

By the way, this loop isn't adding anything to the Collection. It's just overwriting ReProp with new instances of cRealEstate.
 
Upvote 0
Welcome to the Forum!

Can you post your code for the cRealEstate class? My guess is that you're triggering a recursive call in that code.

By the way, this loop isn't adding anything to the Collection. It's just overwriting ReProp with new instances of cRealEstate.

Hi Stephen,

Thank you for your help, below is my Class Module for cRealEstate. Also I have added GameRealEstate.Add ReProp after the End With statement.
When I tried to add a Key GameRealEstate.Add (ReProp, ReProp.Name) I received an compiler error expecting := expression when I add it by (Item:=ReProp, Key:=ReProp.Name) I get Compile error Expected :=

Code:
'Define New Class for Properties
Private reName As String
Private reCost As Integer
Private reRent As Integer
Private reProfit As Integer
Private reMort As Integer
Private reOwner As StringPublic Property Get Name() As String
    Name = reName
End Property
Public Property Let Name(value As String)
If Len(value) > 1 Then
    reName = value
End If
End Property
Public Property Get Cost() As Integer
    Cost = reCost
End Property
'LET
Public Property Let Cost(value As Integer)
If value > 0 Then
    reCost = value
End If
End Property
Public Property Get Rent() As Integer
    Rent = reRent
End Property
'LET
Public Property Let Rent(value As Integer)
If value > 0 Then
    reRent = value
End If
End Property
Public Property Get Profit() As Integer
    Profit = reProfit
End Property
'LET
Public Property Let Profit(value As Integer)
    Profit = value
End Property
Public Property Get Mort() As Integer
    Mort = reMort
End Property
'LET
Public Property Let Mort(value As Integer)
If value > 0 Then
    reMort = value
End If
End Property
Public Property Get Owner() As String
    Owner = reOwner
End Property
Public Property Let Owner(value As String)
If Len(value) > 0 Then
    reOwner = value
End If
End Property
 
Upvote 0
Your Profit Let property is calling itself. It should be:
Rich (BB code):
Public Property Let Profit(value As Integer)
    reProfit = value
End Property
and not:
Rich (BB code):
Public Property Let Profit(value As Integer)
    Profit = value
End Property
 
Upvote 0
Thank you Rory,
You have solved the Stack Out of Space error, Do you know why Public Property Let did not show up in the call stack view?
Do you have any thoughts on the compile error when I try to add to the collection?
 
Upvote 0
Can you post the actual code you used when adding to the Collection?
 
Upvote 0
Do you know why Public Property Let did not show up in the call stack view?

I'd assume you don't have your VBE set up to break in class modules when there's an error. That's why all you see is the code running in the calling module.
 
Upvote 0
Right now I have

Code:
Set GameRealEstate = New Collection
'Populate Real Estate randomly
i = 1
    
    For i = 1 To PropCount
    
       Set ReProp = New cRealEstate
       
        ActiveCell.Offset(Int(100 - 1 + 1) * Rnd + 1).Activate
        
        With ReProp
            .Name = ActiveCell.value
            .Cost = ActiveCell.Offset(0, 1).value
            .Rent = ActiveCell.Offset(0, 2).value
            .Profit = ActiveCell.Offset(0, 3).value
            .Mort = ActiveCell.Offset(0, 4).value
        End With
        
        GameRealEstate.Add ReProp
                                       
        Range("A:A").Find(GLoc).Activate ' Go Back to the City Head
        ActiveCell.Offset(0, 1).Activate ' Go over to the names
                
  Next I

I wanted to use the Name Property as the ID, so I was trying

Code:
Set GameRealEstate = New Collection
'Populate Real Estate randomly
i = 1
    
    For i = 1 To PropCount
    
       Set ReProp = New cRealEstate
       
        ActiveCell.Offset(Int(100 - 1 + 1) * Rnd + 1).Activate
        
        With ReProp
            .Name = ActiveCell.value
            .Cost = ActiveCell.Offset(0, 1).value
            .Rent = ActiveCell.Offset(0, 2).value
            .Profit = ActiveCell.Offset(0, 3).value
            .Mort = ActiveCell.Offset(0, 4).value
        End With
        
        GameRealEstate.Add (ReProp, ReProp.Name)
        
                                       
        Range("A:A").Find(GLoc).Activate ' Go Back to the City Head
        ActiveCell.Offset(0, 1).Activate ' Go over to the names
                
  Next I

And I get a Compile Error Expecting:=

So I thought

Code:
GameRealEstate.Add (Item:= ReProp, Key:= ReProp.Name)

But I get the same error.

I took the syntax from multiple sources including Microsoft website
 
Last edited by a moderator:
Upvote 0
You need to remove the parentheses as you aren't returning a value:

Code:
GameRealEstate.Add Item:=ReProp, Key:=ReProp.Name
 
Upvote 0

Forum statistics

Threads
1,215,890
Messages
6,127,594
Members
449,386
Latest member
owais87

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top