Faustulus
asked on
Set Class Property
I am trying to program a calendar and have created a class for the day buttons which captures the Click event for any of them. For the purpose of handling this event on class level I would like to create a Parent property for the buttons and assign the UserForm to it. This is the code I have,
in the class module 'CalButton'
in the class module 'CalButton'
Public WithEvents CalBtn As MSForms.Label
Public pParent As DatePicker
Public Property Get Parent() As DatePicker
Set CalForm = pParent
End Property
Public Property Set CalForm(CalForm As DatePicker)
Set pParent = CalForm
End Property
Private Sub CalBtn_Click()
MsgBox CalBtn.Name & " was clicked."
Debug.Print CalBtn.Parent.Name ' DOESN'T WORK
End Sub
in the code module of the UserForm (DatePicker - no relation of the Excel form by the same name) Dim Btn() As CalButton
Private Sub AssignCalButtons()
' assign all day button to CalButton class
Dim Ctl As Object
Dim i As Long
ReDim Btn(1 To Me.Controls.Count)
For Each Ctl In Me.Controls
If InStr(1, Ctl.Name, "Day", vbTextCompare) = 1 Then
i = i + 1
Set Btn(i) = New CalButton
Set Btn(i).CalBtn = Ctl
Set Btn(i).Parent = Me ' Compile error: Invalid use of property
End If
Next Ctl
ReDim Preserve Btn(1 To i)
End Sub
The code runs and works without the Parent property idea. What am I doing wrong, and how to do it right?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This could mean either CalButton or CalForm is undefined.
ASKER
CalButton is the name of the class module.
CalForm is defined in the code I posted which is in the class module CalButton.
Where is the mistake?
CalForm is defined in the code I posted which is in the class module CalButton.
Where is the mistake?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you. Your support was was a great relief to me in my hours of trial (and error).
You are welcome!
BTW, I don't use VB.NET at all. It seems I should install VS finally.
Happy New Year!
BTW, I don't use VB.NET at all. It seems I should install VS finally.
Happy New Year!
ASKER
OK. The problem is solved. But can you tell me how I can assign the form as a property of the class?
I have been testing this:
In the class module,
Open in new window
And in the code (actually, the form's code module)Open in new window
It stops at CalButton and claims "Variable no defined".Happy New Year!
Faustulus