Dictionary后期绑定的问题
(创建时间:2012年07月31日 20:45:00)
曹华群 : 

Dictionary后期绑定的问题:

 

加载scrrun.dll 就是前期绑定(引用Microsoft Scripting Runtime,Dim d As New Dictionary ),可以使用d.Keys(1)

 

Private Sub B()
    Dim i As Integer
    Dim d As New Scripting.Dictionary
    d.Add "A1", "1"
    d.Add "A2", "2"
    For i = 0 To d.Count - 1
        Debug.Print d.Keys(i)
    Next
End Sub


 

后期绑定(不引用,Set d = CreateObject("scripting.dictionary"),不能使用d.Keys(1),会出错:property let 过程未定义 property get 过程不返回对象。

 

Private Sub A()
    Dim i As Integer
    Dim d As Object
    Dim k()
    Set d = CreateObject("Scripting.Dictionary")
    d.Add "A1", "1"
    d.Add "A2", "2"
    k = d.Keys  '后绑定方式,不能直接使用:d.Keys(1)
    For i = 0 To d.Count - 1
        Debug.Print k(i)
    Next
End Sub

文档中心