据我了解,VBA 中有三种程序:
- 函数
- 程序
- 属性(property)手续
我在网上搜索过,但没有找到属性过程的明确定义。
最佳答案
属性过程的示例位于自定义类模块内。 可以检索(get)或输入其值(let)
在自定义类中 (clsExample)
Private pName As String
Public Property Get Name() As String
Name = pName
End Property
Public Property Let Name(value As String)
pName = value
End Property
您可以在标准子中使用一个,如下所示:
Sub example()
Dim exampleClass As clsExample
Set exampleClass = New clsExample
exampleClass.Name = "John Smith"
MsgBox (exampleClass.Name)
End Sub
一些优点是您可以为有意义的对象提供有意义的属性名称(即project.id,project.manager),另一个例子是您可以为对象提供只读的派生属性(仅使用get而不使用set) .
关于vba - 究竟什么是属性(property)程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41894863/