Excel 2010 vba数组作为类成员错误

标签 excel vba

我正在做一个项目,遇到了一些我不明白的事情。将数组分配给类成员时,LetGet 名称不能相同。如果是,我会收到错误:

同一属性的属性过程定义不一致,或者属性过程有可选参数、ParamArray 或无效的 Set Final 参数

谁能告诉我我是否只是做错了什么,或者这就是事实。下面的代码生成上述消息。

测试代码:

Sub loadServer()
Dim testServer As AvayaServer
Dim i As Long
Dim arr() As Variant

arr = Array("1", "2", "3", "4", "5")

Set testServer = New AvayaServer
testServer.Name = "This Sucks"
testServer.Skill = arr
MsgBox testServer.Skills(4)
MsgBox testServer.Name

End Sub

类代码:

Private pName As String
Private pSkills() As String
Public Property Get Skills() As Variant
Skills = pSkills()
End Property

Public Property Let Skills(values() As Variant)
ReDim pSkills(UBound(values))
Dim i As Long
For i = LBound(values) To UBound(values)
    pSkills(i) = values(i)
Next
End Property

最佳答案

values() As Variant 更改为 values As Variant:

类别代码:

Private pName As String
Private pSkills() As String
Public Property Get Skills() As Variant
Skills = pSkills()
End Property

Public Property Let Skills(values As Variant)          'Fixed here
ReDim pSkills(UBound(values))
Dim i As Long
For i = LBound(values) To UBound(values)
    pSkills(i) = values(i)
Next
End Property

说明:

values As Variant 将是 Variant 类型,稍后您将用它来存储数组。 values() As Variant 是一个 Variant 类型的数组,不能为其分配 ArrayArray 只能分配给前者。

关于Excel 2010 vba数组作为类成员错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24456670/

相关文章:

excel - 在 Excel 中水平折叠列

vba - 如何获取word 2003文档的模板路径

vba - 无法在 Excel 和 Word 中将用户窗体安装为加载项

r - 如何通过RDCOMClient将VBA "with"函数结构解释为R代码?

vba - 将数据保存到工作表中

excel - 禁止访问 Mac Office 中的 Visual Basic 编辑器

excel - 仅在 Webi 中将原始值导出为 Excel 保留格式

java - apache poi 中的 equals() 方法

vba - Let/Get 属性中的可选参数如何工作?

excel - VBA Excel 比较两个列表是否匹配,在单独的工作表上输出结果