vba - 从集合中的对象获取属性(VBA)
问题描述
我创建了一个自定义类对象的集合,我能够检索除数量属性(这是一个数组)之外的所有对象属性
以下是我的代码
Sub Ledger()
Dim ActPeriod As Long
Dim ForcastPeriod As Long
Dim sth As Worksheet
Dim Account As New ClsAccount
Dim allaccounts As New Collection
ActPeriod = 3
ForecastPeriod = 3
For i = 1 To Sheet1.Range("A4:A26").count
If Sheet1.Cells(i, 1) <> 0 Then
counter = counter + 1
Set Account = New ClsAccount
With Account
.Code = Sheet1.Cells(i, 1)
.Name = Sheet1.Cells(i, 2)
.amount = Sheet1.Range(Cells(i, 3), Cells(i, 2 + ActPeriod))
allaccounts.add Account, .Code
End With
End If
Next i
MsgBox allaccounts(3).amount(1, 1)
End Sub
我用来创建类的代码如下
Private AccAmount As Variant
Private AccGrowth As Variant
Private AccName As String
Private AccCode As String
Property Let amount(amt As Variant)
AccAmount = amt
End Property
Property Get amount() As Variant
amount = AccAmount
End Property
Property Let Name(n As String)
AccName = n
End Property
Property Get Name() As String
Name = AccName
End Property
Property Let Code(c As String)
AccCode = c
End Property
Property Get Code() As String
Code = AccCode
End Property
我收到此错误
解决方案
MsgBox allaccounts(3).amount()(1, 1)
没有括号,VBA 认为您正在尝试传递1, 1
给 Property Get 过程,并且没有使用任何参数定义...
推荐阅读
- java - 如何在 Mongo Spring @Aggreation 中排序?
- android - Android Style 所有片段的背景颜色
- python - Looking for a startswith equivalent for integers in panda
- vue.js - How to make change in child components dynamically from parent in Vue.js
- javascript - How can I initialize multiple nestjs provider with data from JSON?
- python - ModuleNotFoundError:没有名为“plotly.validators.scatter._line”的模块
- python - 如何在 Python 中使用 Selenium 发送网页文本时发送消息?
- grafana - 如何在 Grafana 中为 influxDB 显示 TOP 结果 10?
- java - java实体的继承3级
- java - Java将字符串序列转换为逻辑函数