gpt4 book ai didi

vba - 究竟什么是属性(property)程序?

转载 作者:行者123 更新时间:2023-12-03 00:50:29 24 4
gpt4 key购买 nike

据我了解,VBA 中有三种程序:

  1. 函数
  2. 程序
  3. 属性(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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com