Solved

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

Posted on 2009-07-07
4
255 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 142

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now