Solved

Run-time error '28': Out of stack space

Posted on 2009-07-07
4
258 Views
Last Modified: 2012-05-07
This line...

clsVendor.Name = sVendor

...produces this error...

Run-time error '28': Out of stack space

I've highlighted the offending line with a box of ***. Does anyone know what is causing this error?
'Code in worksheet module:
 
Private Sub CommandButton1_Click()
    
    Dim wkb1 As Workbook, wkb2 As Workbook
    Dim lRowCounter As Long, lColumnCounter As Long
    Dim sFullName1 As String, sFileName1 As String, sFullName2 As String, sFileName2 As String
    Dim sVendor As String
    Dim dTotalCost As Double, dTotalSales As Double
 
    'sFullName1 = "\\msfs05.lowes.com\DATA1\SHARE\Lognet\Channel Change Process\13. IP&E Planning\Templates\Template ProForma Comp\JBK Examples\Data Collection Fields_v13 Routine.xls"
    sFullName1 = "C:\Documents and Settings\dpark\Desktop\Data Collection Fields_v13 Routine.xls"
    sFileName1 = sGetFileName(sFullName1)
    
    'sFullName2 = "\\msfs05.lowes.com\DATA1\SHARE\Lognet\Channel Change Process\13. IP&E Planning\Templates\Template ProForma Comp\JBK Examples\2009 L&G Fall Equipment_Program Sheet.xls"
    sFullName2 = "C:\Documents and Settings\dpark\Desktop\2009 L&G Fall Equipment_Program Sheet.xls"
    sFileName2 = sGetFileName(sFullName2)
      
    'Make sure both workbooks open
    If bIsWorkbookOpen(sFileName1) Then
        Set wkb1 = Workbooks(sFileName1)
        wkb1.Activate
    Else
        Set wkb1 = Workbooks.Open(Filename:=sFullName1)
        wkb1.Activate
    End If
        
    If bIsWorkbookOpen(sFileName2) Then
        Set wkb2 = Workbooks(sFileName2)
    Else
        Set wkb2 = Workbooks.Open(Filename:=sFullName2)
    End If
    
'    Dim mcolVendors As New Collection
    
    lRowCounter = 20
    lColumnCounter = 2
    
    With wkb2.Worksheets("2009")
        Do Until IsEmpty(.Cells(lRowCounter, "B"))
            sVendor = .Cells(lRowCounter, "B").Value
            
            AddVendor sVendor, lRowCounter
            If mcolVendors(sVendor) Is Nothing Then
                AddVendor sVendor, lRowCounter
            End If
                        
            mcolVendors(sVendor).TotalCost = mcolVendors(sVendor).TotalCost + .Cells(lRowCounter, "N").Value
            mcolVendors(sVendor).TotalSales = mcolVendors(sVendor).TotalSales + .Cells(lRowCounter, "O").Value
        Loop
    End With
End Sub
 
'Code in standard module:
 
Sub AddVendor(sVendor As String, lRowCounter As Long)
    Dim clsVendor As CVendor
    With Workbooks("2009 L&G Fall Equipment_Program Sheet.xls").Worksheets("2009")
        Set clsVendor = New CVendor
***********************************************
**      clsVendor.Name = sVendor      **
***********************************************
        mcolVendors.Add clsVendor, sVendor
    End With
End Sub
 
'Code in class module
 
Private dSumCost As Double
Private dSumSales As Double
 
Property Let Name(sVendor)
    Name = sVendor
End Property
 
'Sum TotalCost values
Property Let TotalCost(dTotalCost As Double)
    TotalCost = TotalCost + dTotalCost
End Property
 
'Sum TotalSales values
Property Let TotalSales(dTotalSales As Double)
    TotalSales = TotalSales + dTotalSales
End Property
 
'Return TotalCost
Property Get TotalCost() As Double
    TotalCost = TotalCost
End Property
 
'Return TotalSales
Property Get TotalSales() As Double
    TotalSales = TotalSales
End Property
 
Public Function PercentMargin() As Double
    GetPercentMargin = (TotalSales1 - TotalCost1) / TotalSales1
End Function

Open in new window

0
Comment
Question by:ltdanp22
  • 2
4 Comments
 

Author Comment

by:ltdanp22
ID: 24796509
Additional Info:

The code enters and then re-runs this line until the Out of stack space error pops up...

Property Let Name(sVendor)
    Name = sVendor
End Property

Is Name a reserved word?
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 24796521
I think that we need to know more about what CVendor is. However, you should be aware that Out-of-stack space errors are usually caused by a runaway recursion loop.
0
 

Author Closing Comment

by:ltdanp22
ID: 31600715
syntax of property let was wrong. need to instantiate private variables and set them equal to argument
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24797494
Property Let Name(sVendor)
    Name = sVendor
End Property

means that on this line:
Name = sVendor

you call the property let method again... and again ... and again...

instead, it should assign to a class -level variable




private _Name as string 
Public Property Let Name(sVendor as string)
    _Name = sVendor
End Property 
Public Property Get Name as string
    Name = _Name
End Property

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

839 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