Reputation: 49
I'm getting a run-time error 451 when attempting to retrieve a dictionary as a property of my class. It says
Property let procedure note defined and property get procedure did not return an object.
Here is the main subroutine code and then the class code, in the main subroutine the first message box works wheras the second message box (which I'm intending on returning the same data as the first) throws the error:
The main module:
Sub Main()
'Declaring [BD]
Dim oHeaderDictionary As New Scripting.Dictionary
'Initializing [BD]
Set oThisSlider = New Slider
Set oHeaderDictionary = New Scripting.Dictionary
Worksheets("Options").Activate
iLastRow = bpLastRow("B")
For iRowIncrementer = 3 To iLastRow
sColumnHeaders = Cells(iRowIncrementer, 2).Value
sColumnStyles = Cells(iRowIncrementer, 3).Value
oHeaderDictionary.Add sColumnHeaders, sColumnStyles
Next iRowIncrementer
MsgBox oHeaderDictionary.Items(1)
oThisSlider.Headers = oHeaderDictionary
MsgBox oThisSlider.Headers.Items(1)
End Sub
And the class module:
'Declaring [BD]
Private m_oHeaders As Scripting.Dictionary
'Initializing [BD]
'==========================================================================================
' [BD] Properties
'==========================================================================================
Property Get Headers() As Scripting.Dictionary
Set Headers = m_oHeaders
End Property
Property Let Headers(oHeaders As Scripting.Dictionary)
Set m_oHeaders = oHeaders
End Property
Any ideas on why this error is occurring and what to do?
Upvotes: 1
Views: 158
Reputation: 160
Option Explicit is your friend. You've got to declare oThisSlider as a Slider object for it to work.
Option Explicit
Sub Main()
'Declaring [BD]
Dim oHeaderDictionary As New Scripting.Dictionary
Dim oThisSlider As Slider
Dim iLastRow As Long
Dim iRowIncrementer As Long
Dim sColumnHeaders As String
Dim sColumnStyles As String
'Initializing [BD]
Set oThisSlider = New Slider
Set oHeaderDictionary = New Scripting.Dictionary
Worksheets("Options").Activate
iLastRow = bpLastRow("B")
For iRowIncrementer = 3 To iLastRow
sColumnHeaders = Cells(iRowIncrementer, 2).Value
sColumnStyles = Cells(iRowIncrementer, 3).Value
oHeaderDictionary.Add sColumnHeaders, sColumnStyles
Next iRowIncrementer
MsgBox oHeaderDictionary.Items(1)
oThisSlider.Headers = oHeaderDictionary
MsgBox oThisSlider.Headers.Items(1)
End Sub
Upvotes: 1