I am getting a compile error on the following attempt to pass a date from range in a spreadsheet to a property in a custom class module.
"Definitions of property procedures for the same property are inconsistent....."
I have a custom class called Asset and a custom Collection called Portfolio. In a standard module I add object to the collection in a loop. In that loop I call a FillFromSheet method for a property in the clsAsset class object. This passes my values to the properties.
The FillfromSheet method loads two data values from two ranges in a spreadsheet and passes 2 values to 2 properties in the Asst Class.
The ranges are pulled into the FillfromSheet and resized as only a portion of the range is required. This is passed to the clsAsset properties.
The code stops in the clsAsset class module with the compile error
STANDARD MODULE
'Declare Public Objects
Public asset As clsAsset
Public portfolio As clsPortfolio
Sub CreateObjects()
'*****************
' Objects
Set EventTablerng = Range("XYZ")
Set portfolio = New clsPortfolio
portfolio.FillFromSheet EventTablerng
End Sub
CLASS MODULE(clsPortfolio)
Public Sub FillFromSheet(rng1)
Dim i As Long
Dim obj As clsAsset
'Add objects to collection
For i = 1 To rng1.Rows.Count
'Create new instance of class
Set obj = New clsAsset
With rng1
obj.Month1EventStartDate = rng1.Resize(1, 2).Offset(i, 0)
obj.Month1EventEndDate = rng1.Resize(1, 3).Offset(i, 0)
obj.Month1EventDays = obj.Month1EventEndDate - obj.Month1EventStartDate
End With
'create Object and Loop
Me.Add obj
Next
End Sub
CLASS MODULE(clsAsset)
Private m_sMonth1EventStartDate As Date
Private m_sMonth1EventEndDate As Date
Private m_sMonth1EventDays As Single
Public Property Set Month1EventStartDate(Value As Range)
End Property
Public Property Set Month1EventEndDate(Value As Range)
End Property
Public Property Set Month1EventDays(Value As Single) 'check this
m_sMonth1EventDays
End Property
"Definitions of property procedures for the same property are inconsistent....."
I have a custom class called Asset and a custom Collection called Portfolio. In a standard module I add object to the collection in a loop. In that loop I call a FillFromSheet method for a property in the clsAsset class object. This passes my values to the properties.
The FillfromSheet method loads two data values from two ranges in a spreadsheet and passes 2 values to 2 properties in the Asst Class.
The ranges are pulled into the FillfromSheet and resized as only a portion of the range is required. This is passed to the clsAsset properties.
The code stops in the clsAsset class module with the compile error
STANDARD MODULE
'Declare Public Objects
Public asset As clsAsset
Public portfolio As clsPortfolio
Sub CreateObjects()
'*****************
' Objects
Set EventTablerng = Range("XYZ")
Set portfolio = New clsPortfolio
portfolio.FillFromSheet EventTablerng
End Sub
CLASS MODULE(clsPortfolio)
Public Sub FillFromSheet(rng1)
Dim i As Long
Dim obj As clsAsset
'Add objects to collection
For i = 1 To rng1.Rows.Count
'Create new instance of class
Set obj = New clsAsset
With rng1
obj.Month1EventStartDate = rng1.Resize(1, 2).Offset(i, 0)
obj.Month1EventEndDate = rng1.Resize(1, 3).Offset(i, 0)
obj.Month1EventDays = obj.Month1EventEndDate - obj.Month1EventStartDate
End With
'create Object and Loop
Me.Add obj
Next
End Sub
CLASS MODULE(clsAsset)
Private m_sMonth1EventStartDate As Date
Private m_sMonth1EventEndDate As Date
Private m_sMonth1EventDays As Single
Public Property Set Month1EventStartDate(Value As Range)
End Property
Public Property Set Month1EventEndDate(Value As Range)
End Property
Public Property Set Month1EventDays(Value As Single) 'check this
m_sMonth1EventDays
End Property