I came across this bit of vba code posted in another SO question. Is there any significance in referencing the Set property in the Get Property of a class?
Private WithEvents mctlEventButton As MSForms.CommandButton
Public Property Set EventButton(ctlButton As MSForms.CommandButton)
Set mctlEventButton = ctlButton
End Property
Why do this? …
Public Property Get EventButton() As MSForms.CommandButton
Set EventButton = mctlEventButton
End Property
The code was showing how to use collections to iterate through a group of controls. The question wasnt really about that part of the code, so it wasnt addressed in the question. Using the example from the question, I ran into an issue with the bit I posted here because the Get Property was using the Set property. So when would that be useful?
Here is the link to the SO Question: object array or collection in VBA Excel
In the code above,
Set EventButton = mctlEventButtonwon’t call the following (try stepping through the code & you will see that it doesn’t step intoSet)On the other hand, this of it as a statement that is used to return a value.
Effectively, think of
Getaswrapped in form of a property for developers to do get/set.