vba - 如何在 VBA 中使用静态数组作为类属性

标签 vba excel

我在 MyClass2 中有以下属性:

 Private MyClass1Array(1 To 4) As MyClass1

其中 MyClass1 是我定义的另一个类。我不知道如何处理这个属性:它不能设置为 public,所以我在 MyClass2 模块中写了这个:
Public Property Let SetMyClass1Array(i As Integer, c As MyClass1)
    MyClass1Array(i) = c
End Property

Public Property Get GetMyClass1Array(i As Integer) As MyClass1
    GetMyClass1Array = MyClass1Array(i)
End Property

但这也行不通。如何正确编写此属性?谢谢!

最佳答案

使用类对象时,需要使用 Set当您处理对象引用而不是原始数据类型值时。

Public Property Let SetMyClass1Array(i As Integer, c As MyClass1)
    Set MyClass1Array(i) = c
End Property

Public Property Get GetMyClass1Array(i As Integer) As MyClass1
    Set GetMyClass1Array = MyClass1Array(i)
End Property

关于vba - 如何在 VBA 中使用静态数组作为类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13157400/

相关文章:

vba - 循环遍历集合的成员,如何获取成员的 key ?

vba - Excel VBA : How do I assign a range to a variable?

python - VBA如何使用部分参数调用另一个函数内的函数

python - Excel保存过程中字符错误

excel - Excel VBA - 格式 ("7A", "00") 输出 "00"而格式 ("7B", "00") 导致所需的输出 "7A"。为什么它们不同?

vba - 使用 VBA 将公式分配给 Excel 单元格

Excel日期舍入计算

excel - Selenium VBA Excel - 在 iframe 中单击链接时出现问题

sql-server - 仅使用正确的参数顺序在 Access VBA 中调用存储过程,为什么?

vba - VBA 中 .GetOpenFileName 的多选错误