【问题标题】:Invalid procedure call or argument error vb 6无效的过程调用或参数错误 vb 6
【发布时间】: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


【解决方案1】:

当一个collection中没有key的item时,需要添加一个,并给它一个值,如下所示。

For Each value In strserviceChecked_GL
    If Not Exists(counts,value) Then
        ' Key 'value' is not in 'counts' collection.
        ' Add key 'value', and give it the value 1.
        counts.Add 1, CStr(value)
        'counts.Item(value) = 1
    Else
        counts.Item(value) = counts.Item(value) + 1
    End If
Next

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    • 2018-07-25
    • 1970-01-01
    相关资源
    最近更新 更多