有没有办法区分 VBA 中同名的类成员和属性/子/函数参数?例如:
第一类:
Private Name As String
Property Let LastName(Name As String)
this.Name = Name
End Property
Property Get LastName() As String
Dim Name As String
Name = "Mr. "
LastName = Name & this.Name
End Property
在其他语言中,您可以使用关键字 this
来引用类/实例(?) 成员。但是VBA中是如何解决的呢?我知道你可以使用不同的名字。但这不是我想要的。
感谢您的帮助!
最佳答案
您可以使用 Mathieu 在 private-this-as-tsomething 中教给我们的类型来创建 This
只需使用变量创建一个类型并将其分配给 This。
Private Type TPerson
Name As String
End Type
Private This As TPerson
Property Let LastName(Name As String)
This.Name = Name
End Property
Property Get LastName() As String
Dim Name As String
Name = "Mr. "
LastName = Name & This.Name
End Property
不要忘记阅读有关 RubberDuckVBA 的其他文章,因为它们提供了许多有关 VBA-OOP 的精彩见解。
关于vba - 区分VBA中同名的类成员和参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55082887/