Vba 从Get属性引用Set属性
我在另一个问题中遇到了这段vba代码。在类的Get属性中引用Set属性有什么意义吗Vba 从Get属性引用Set属性,vba,class-design,Vba,Class Design,我在另一个问题中遇到了这段vba代码。在类的Get属性中引用Set属性有什么意义吗 Private with events mctlEventButton As MSForms.CommandButton 公共属性设置事件按钮(ctlButton作为MSForms.CommandButton) 设置mctlEventButton=ctlButton End属性 为什么要这样做 公共属性以MSForms.CommandButton的形式获取EventButton() Set EventButton
Private with events mctlEventButton As MSForms.CommandButton
公共属性设置事件按钮(ctlButton作为MSForms.CommandButton)
设置mctlEventButton=ctlButton
End属性
为什么要这样做
公共属性以MSForms.CommandButton的形式获取EventButton()
Set EventButton=mctlEventButton
End属性
代码展示了如何使用集合
迭代一组控件。问题并不是关于代码的那一部分,所以问题中没有提到。使用问题中的示例,我在这里发布的位遇到了一个问题,因为Get属性使用Set属性。那什么时候有用呢
以下是SO问题的链接:
在上面的代码中,Set EventButton=mctlEventButton
不会调用以下命令(尝试单步执行代码&您将看到它不会单步执行Set
)
另一方面,这是一个用于返回值的语句。实际上,将
Get
视为
Public function EventButton() As MSForms.CommandButton
Set EventButton = mctlEventButton 'returning the value from the function
End Property
以属性的形式包装,供开发人员执行get/set。我有一个完整的回复,关于当我进入代码时,它是如何进入
set
语句的。然后我意识到我的Get
和Set
属性的命名不同。让他们同名会产生你描述的行为。谢谢你的解释。:)
Public Property Set EventButton(ctlButton As MSForms.CommandButton)
Set mctlEventButton = ctlButton
End Property
Public function EventButton() As MSForms.CommandButton
Set EventButton = mctlEventButton 'returning the value from the function
End Property