vb中collection附加数据时的行为
在collection中加入基本类型后,原数据改变不会影响collection中的数据
在collection中加入一个自定类后,原数据改变会影响collection中的数据 例如:测试代码中的 a.Add aa
测试代码:
Dim a As New Collection
Private Sub Form_Load()
Dim b As Integer, c As Integer
Dim aa As New Class1
Dim x(3) As Integer
b = 1
c = 2
aa.cc = 5
x(0) = 1
x(1) = 2
x(2) = 3
a.Add b
a.Add c
a.Add aa
a.Add x
b = 3
aa.cc = 8
x(0) = 4
x(1) = 5
x(2) = 6
Debug.Print a.Item(1)
Debug.Print a.Item(2)
Debug.Print a.Item(3).cc
Debug.Print a.Item(4)(0)
aa.cc = 6
Set aa = Nothing
Debug.Print a.Item(3).cc
End Sub
Private Sub Command1_Click()
Debug.Print a.Item(1)
Debug.Print a.Item(2)
Debug.Print a.Item(3).cc
Debug.Print a.Item(4)(0)
End Sub