【发布时间】:2019-07-29 15:40:41
【问题描述】:
我有以下代码:
我在 counts.Item(value) = 1 中遇到错误。
Set xmlNodeList = xmlEncounter.documentElement.selectNodes("//BillingLIne/Receipts")
If xmlNodeList.length > 1 Then
For i_Loop1 = 1 To xmlNodeList.length
strserviceChecked_GL(i_Loop1) = xmlNodeList.Item(i_Loop1 - 1).Attributes.getNamedItem("ServiceID").nodeValue
Id1tobechecked_GL(i_Loop1) = xmlNodeList.Item(i_Loop1 - 1).Attributes.getNamedItem("Receptid1").nodeValue
Id2tobechecked_GL(i_Loop1) = xmlNodeList.Item(i_Loop1 - 1).Attributes.getNamedItem("Receptid2").nodeValue
Id3tobechecked_GL(i_Loop1) = xmlNodeList.Item(i_Loop1 - 1).Attributes.getNamedItem("Receptid3").nodeValue
Id4tobechecked_GL(i_Loop1) = xmlNodeList.Item(i_Loop1 - 1).Attributes.getNamedItem("Receptid4").nodeValue
Next i_Loop1
End If
Dim value As Variant
Dim counts As Collection
Set counts = New Collection
For Each value In strserviceChecked_GL
If Not Exists(counts,value) Then
counts.Item(value) = 1
Else
counts.Item(value) = counts.Item(value) + 1
End If
Next
Public Function Exists(ByVal oCol As Collection, ByVal vKey As Variant) As Boolean
On Error Resume Next
oCol.Item vKey
Exists = (Err.Number = 0)
Err.Clear
End Function
【问题讨论】:
-
您可能会收到该消息,因为
counts是一个新的(空)集合,并且您正试图在其中设置一个项目。您首先需要向集合中添加一个新项目。
标签: dictionary collections vb6