Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 8
Default Custom class, Stack overflow error

Hi

I have written a class module but when I try to load more than one variable Excel gives me a type 28 error, Google says that it is a memory issue but if it won't even load two strings there must be an error with my code, can someone point out where I have made the mistake please?

My class module is:

Code:
Private pEmpID As String
Private pStartDate As Date
Private pEndDate As Date
Private pStatus As String
Private pHolType As String
Private pShift As String

Public Property Let strEmpID(EmpID As String)
pEmpID = EmpID
End Property

Public Property Get strEmpID() As String
strEmpID = pEmpID
End Property

Public Property Let strStartDate(StartDate As Date)
strStartDate = StartDate
End Property

Public Property Get strStartDate() As Date
pStartDate = strStartDate
End Property

Public Property Let strEndDate(EndDate As Date)
strEndDate = EndDate
End Property

Public Property Get strEndDate() As Date
pEndDate = strEndDate
End Property

Public Property Let strStatus(Status As String)
strStatus = Status
End Property

Public Property Get strStatus() As String
pStatus = strStatus
End Property

Public Property Let strHolType(HolType As String)
strHolType = HolType
End Property

Public Property Get strHolType() As String
pHolType = strHolType
End Property

Public Property Let strShift(Shift As String)
strShift = Shift
End Property

Public Property Get strShift() As String
pShift = strShift
End Property
And my Sub in a normal module is
Code:
Sub Refusetest()
    Dim iHol As clsHoliday
    Set iHol = New clsHoliday
    'With Sheets("MyTime")
        iHol.strEmpID = "EmpID1"
        iHol.strShift = "Shift1"
        'iHol.strStartDate = #1/21/2015#
        'iHol.strEndDate = #1/28/2015#
        'iHol.strHolType = "Type1"
    'End With
    MsgBox iHol.strEmpID
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Custom class, Stack overflow error

Hi David,

I do not have excel at home (coz i am using iMac at home:). therefore could not go through all. But seems like you have a 0 division error.
Can you check whole the variables again, one of them should appear 0.
Cheers
Baha
  #3   Report Post  
Junior Member
 
Posts: 8
Default

Quote:
Originally Posted by View Post
Hi David,

I do not have excel at home (coz i am using iMac at home:). therefore could not go through all. But seems like you have a 0 division error.
Can you check whole the variables again, one of them should appear 0.
Cheers
Baha
How do I check them? When I run the sub, iHol.strShift = "" but that is the line it crashes on. The macro is only there to test that the class works, nothing is done to them apart from opening a message box.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Custom class, Stack overflow error

Hi David,

I do not have excel at home (coz i am using iMac at home:). therefore
could not go through all. But seems like you have a 0 division error.
Can you check whole the variables again, one of them should appear
0. Cheers Baha


I assume *what you really mean is* - you haven't installed a Mac
version of MS Office on your iMac machine!<g

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Custom class, Stack overflow error

Hi

I have written a class module but when I try to load more than one
variable Excel gives me a type 28 error, Google says that it is a
memory issue but if it won't even load two strings there must be an
error with my code, can someone point out where I have made the
mistake please?

My class module is:


Code:
--------------------
Private pEmpID As String
Private pStartDate As Date
Private pEndDate As Date
Private pStatus As String
Private pHolType As String
Private pShift As String

Public Property Let strEmpID(EmpID As String)
pEmpID = EmpID
End Property

Public Property Get strEmpID() As String
strEmpID = pEmpID
End Property

Public Property Let strStartDate(StartDate As Date)
strStartDate = StartDate
End Property

Public Property Get strStartDate() As Date
pStartDate = strStartDate
End Property

Public Property Let strEndDate(EndDate As Date)
strEndDate = EndDate
End Property

Public Property Get strEndDate() As Date
pEndDate = strEndDate
End Property

Public Property Let strStatus(Status As String)
strStatus = Status
End Property

Public Property Get strStatus() As String
pStatus = strStatus
End Property

Public Property Let strHolType(HolType As String)
strHolType = HolType
End Property

Public Property Get strHolType() As String
pHolType = strHolType
End Property

Public Property Let strShift(Shift As String)
strShift = Shift
End Property

Public Property Get strShift() As String
pShift = strShift
End Property
--------------------


And my Sub in a normal module is

Code:
--------------------
Sub Refusetest()
Dim iHol As clsHoliday
Set iHol = New clsHoliday
'With Sheets("MyTime")
iHol.strEmpID = "EmpID1"
iHol.strShift = "Shift1"
'iHol.strStartDate = #1/21/2015#
'iHol.strEndDate = #1/28/2015#
'iHol.strHolType = "Type1"
'End With
MsgBox iHol.strEmpID
End Sub
--------------------


I don't see where you destroy each instance of your class object that
this code creates. You new to clear its space in memory...

Sub Refusetest()
Dim iHol As clsHoliday
Set iHol = New clsHoliday

On Error GoTo Cleanup
'With Sheets("MyTime")
iHol.strEmpID = "EmpID1"
iHol.strShift = "Shift1"
'iHol.strStartDate = #1/21/2015#
'iHol.strEndDate = #1/28/2015#
'iHol.strHolType = "Type1"
'End With
MsgBox iHol.strEmpID

Cleanup:
Set iHol = Nothing
End Sub

...so you don't consume multiple blocks of memory. Optionally, you could
create a global instance at project startup and destroy it at
shutdown...

In a standard module named "m_OpenClose", declare all your global
variables:
Option Explicit

Public oHol As clsHoliday
'*Note data type prefix change from integer to object*

Sub Auto_Open()
InitGlobals
'//other startup code...
End Sub 'Auto_Open

Sub Auto_Close()
Set oHol = Nothing
End Sub 'Auto_Close

Sub InitGlobal()
' Initializes all global variables

Set oHol = New clsHoliday
'//init other public variables as required
End Sub 'InitGlobals

...then modify your procedure as follows...


Sub Setup_HolProps()
' Sets oHol property values
' I'd rewrite this to use values from a worksheet instead of
' hard-coding them here, so this procedure is reusable.

With oHol
.strEmpID = Range("EmpID").Value: .strShift = Range("Shift").Value
'oHol.strStartDate = Range("StartDate").Value
'.strEndDate = Range("EndDate").Value
'.strHolType = Range("HolType").Value
MsgBox .strEmpID
End With 'oHol
End Sub

...where the refs are to local scope (sheet-level) defined name ranges.
This will allow you to edit the worksheet, then process the changes.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Custom class, Stack overflow error

Typo...

I don't see where you destroy each instance of your class object that

this code creates. You need to clear its space in memory...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #7   Report Post  
Junior Member
 
Posts: 8
Default

[quote]
I don't see where you destroy each instance of your class object that
this code creates. You new to clear its space in memory...

Sub Refusetest()
Dim iHol As clsHoliday
Set iHol = New clsHoliday

On Error GoTo Cleanup
'With Sheets("MyTime")
iHol.strEmpID = "EmpID1"
iHol.strShift = "Shift1"
'iHol.strStartDate = #1/21/2015#
'iHol.strEndDate = #1/28/2015#
'iHol.strHolType = "Type1"
'End With
MsgBox iHol.strEmpID

Cleanup:
Set iHol = Nothing
End Sub

...so you don't consume multiple blocks of memory. [quote]

Thank you, but both of those still have the same issue at the same point. Have I made a mistake in declaring the class?
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Custom class, Stack overflow error

In your class change

Public Property Let strShift(Shift As String)
strShift = Shift
End Property

to

Public Property Let strShift(Shift As String)
pShift= Shift
End Property

Regards,
Peter T



"davidman" wrote in message
...

Hi

I have written a class module but when I try to load more than one
variable Excel gives me a type 28 error, Google says that it is a memory
issue but if it won't even load two strings there must be an error with
my code, can someone point out where I have made the mistake please?

My class module is:


Code:
--------------------
Private pEmpID As String
Private pStartDate As Date
Private pEndDate As Date
Private pStatus As String
Private pHolType As String
Private pShift As String

Public Property Let strEmpID(EmpID As String)
pEmpID = EmpID
End Property

Public Property Get strEmpID() As String
strEmpID = pEmpID
End Property

Public Property Let strStartDate(StartDate As Date)
strStartDate = StartDate
End Property

Public Property Get strStartDate() As Date
pStartDate = strStartDate
End Property

Public Property Let strEndDate(EndDate As Date)
strEndDate = EndDate
End Property

Public Property Get strEndDate() As Date
pEndDate = strEndDate
End Property

Public Property Let strStatus(Status As String)
strStatus = Status
End Property

Public Property Get strStatus() As String
pStatus = strStatus
End Property

Public Property Let strHolType(HolType As String)
strHolType = HolType
End Property

Public Property Get strHolType() As String
pHolType = strHolType
End Property

Public Property Let strShift(Shift As String)
strShift = Shift
End Property

Public Property Get strShift() As String
pShift = strShift
End Property
--------------------


And my Sub in a normal module is

Code:
--------------------
Sub Refusetest()
Dim iHol As clsHoliday
Set iHol = New clsHoliday
'With Sheets("MyTime")
iHol.strEmpID = "EmpID1"
iHol.strShift = "Shift1"
'iHol.strStartDate = #1/21/2015#
'iHol.strEndDate = #1/28/2015#
'iHol.strHolType = "Type1"
'End With
MsgBox iHol.strEmpID
End Sub
--------------------




--
davidman



  #9   Report Post  
Junior Member
 
Posts: 8
Default

Quote:
Originally Posted by Peter T[_7_] View Post
In your class change

Public Property Let strShift(Shift As String)
strShift = Shift
End Property

to

Public Property Let strShift(Shift As String)
pShift= Shift
End Property

Regards,
Peter T
I knew there was something wrong with my code! Thanks.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stack Overflow Steven Excel Programming 1 January 5th 09 05:04 PM
Overflow error, need help mkerstei[_15_] Excel Programming 3 July 14th 06 03:10 AM
Overflow Error DG Excel Discussion (Misc queries) 3 April 15th 05 05:45 PM
Application Run Time Error 1004 and Stack Error ExcelMonkey[_190_] Excel Programming 9 February 11th 05 04:48 PM
Why I get "Stack overflow" err 28 mike Excel Programming 0 July 29th 04 10:24 AM


All times are GMT +1. The time now is 07:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"