问题描述
我有一个Client
类.在该类内部,有一个数组losses
.首先,我创建一个clientsColl
数组并向其填充客户端.然后,对于该阵列中的每个客户端,我将填充其losses
阵列.
I have a Client
class. Inside that class there is an array losses
. First I create and populate with clients a clientsColl
array. Then for each client in that array I populate its losses
array.
然后,我尝试为每个客户端将losses
的第一个元素打印到调试中.但是,它不起作用,并显示Property let procedure not defined and property get procedure did not return an object
错误.
Then I try to print into debug a first element of losses
for each client. However, it doesnt work and Property let procedure not defined and property get procedure did not return an object
error appears.
同时,如果我尝试为第一个客户端显示losses
的第一个元素,而没有任何循环,则可以正常工作:
And the same time if I just try to display a first element of losses
for the first client, without any cycle, it works fine:
Dim clientsColl() As Client
clientsColl = getClients(dataWorkbook)
Dim clientCopy As Variant
Debug.Print "first: " & clientsColl(1).getLosses(1) 'works fine
For Each clientCopy In clientsColl
Debug.Print "in for each: " & clientCopy.getLosses(1) 'error here
Next
在Client
类中:
Public Property Get getLosses()
getLosses = losses
End Property
Private losses() As Double
losses
数组的填充方式:
Public Sub calculateFinancialResult()
ReDim losses(1 To simulationCount)
ReDim profits(1 To simulationCount)
Dim i As Long
For i = 1 To simulationCount
If outcomes(i) = 1 Then
losses(i) = totalLoss
...
Else
...
End If
Next
End Sub
为什么会发生这种情况以及如何解决?
Why does this happen and how to fix it?
更多主要子内容:
For Each clientCopy In clientsColl
clientCopy.setSimulationCount = globals("SIMULATION_COUNT")
...
clientCopy.calculateFinancialResult
...
Next
同时,一个简单的for
循环也可以正常工作:
At the same time a simple for
cycle works fine:
Debug.Print "first: " & clientsColl(1).getLosses(1)
For tempCount = LBound(clientsColl) To UBound(clientsColl)
Debug.Print "in for each: " & _
clientsColl(tempCount).getLosses(1)
Next
推荐答案
您的getLosses
属性不带参数,因此您的语法实际上是错误的,即使VBA可以在早期绑定时对其进行处理.您应该使用:
Your getLosses
property doesn't take an argument so your syntax is actually wrong, even though VBA can cope with it when early bound. You should be using:
Debug.Print "first: " & clientsColl(1).getLosses()(1) 'works fine
For Each clientCopy In clientsColl
Debug.Print "in for each: " & clientCopy.getLosses()(1) 'error here
Next
这篇关于Excel VBA:未定义属性让过程,属性获取过程未返回对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!