在下面的循環中,我將Class對象添加到另一個類對象中的集合,該對象本身位於集合中。將VBA對象數據覆蓋在集合中
Dim opportunity As New ClmOpportunity
opportunity.name = name
owners.item(overallOwner).addOpportunity opportunity
MsgBox opportunity.name
Next i
MsgBox owners("John Smith").opportunities(1).name
第一個消息框給出了正確的機會名稱,但第二個消息框被設置爲加入,儘管約翰·史密斯是第一個集合中的最後機會。
因此,如果我有兩個業主,約翰史密斯與機會1和瑪麗樓與機會2從第二個消息框輸出將兩個記錄的機會2。
但是第一條消息將如預期的那樣成爲機會1和2。
這是從所有者類模塊代碼:
Public name As Variant
Public opportunities As New collection
Public Function addOpportunity(opp As ClmOpportunity)
Dim OppID As String
OppID = opportunities.count + 1
opp.ID = OppID
opportunities.Add opp, OppID
End Function
打我吧! –