什么是财产程序?

Rol*_*and 2 excel vba excel-vba

据我所知,在VBA中有三种程序:

  1. 功能
  2. 程序
  3. 物业程序

我在网上搜索,但没有找到明确的财产程序定义.

Zer*_*erk 5

属性过程的示例将在自定义类模块中.可以检索(获取)或输入值(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
Run Code Online (Sandbox Code Playgroud)

您可以在标准子中使用一个如下:

Sub example()

Dim exampleClass As clsExample
Set exampleClass = New clsExample
exampleClass.Name = "John Smith"
MsgBox (exampleClass.Name)

End Sub
Run Code Online (Sandbox Code Playgroud)

一些优点是您可以为有意义的对象提供有意义的属性名称(即project.id,project.manager),另一个示例是您可以为对象提供只读的属性(仅使用get和no set).

  • 您实际上可以向*any*模块添加属性,包括标准模块. (5认同)