小编Dav*_*vis的帖子

VBA和集合 - 在添加到集合之前需要将实例设置为空?

我试图用一个集合的修改值添加一个对象两次,但是在集合的末尾包含两个项目的相同值.我哪里错了?

Private Sub MySub()
    Dim ClientList As Collection
    Set ClientList = New Collection

    Dim Inst1 As Client

    Set Inst1 = New Client

    Inst1.Code = 1
    Inst1.Name = "First Client"
    'Adding first client
    ClientList.Add Inst1 

    Inst1.Code = 2
    Inst1.Name = "Second Client"
    'Adding second client
    ClientList.Add Inst1

    Set Inst1 = ClientList(1)
    MsgBox Inst1.Name 'Show "Second Client"   

    Set Inst1 = ClientList(2)
    MsgBox Inst1.Name 'Show "Second Client" too   


End Sub
Run Code Online (Sandbox Code Playgroud)

collections vba multiple-instances

2
推荐指数
1
解决办法
1534
查看次数

标签 统计

collections ×1

multiple-instances ×1

vba ×1