我有这样的代码:VBA:我改变了ARR(0),不明白为什么ARR(1)改变了?
Call MakeRoomForArrayItem(interAll, 0)
interAll(0).StartY = tempStartY
interAll(0).K = tempK
在我被一个成功地创建一个新的细长interAll()的第一行。
然后我希望第二行和第三行仅影响interAll(0),但它们对interAll(1)执行相同的更改。为什么是这样?我没有成功创建interAll(1)的新对象吗?
Sub MakeRoomForArrayItem(ItemArray As Variant, ByVal ItemElement As Integer)
Dim i As Integer
ReDim Preserve ItemArray(LBound(ItemArray) To UBound(ItemArray) + 1)
For i = UBound(ItemArray) - 1 To ItemElement Step -1
Set ItemArray(i + 1) = ItemArray(i)
Next
'Erase values in object ItemArray(ItemElement) would be nice
End Sub
我在其他情况下成功地使用了相同的功能。它可能与调用函数中缺少声明有关吗?
编辑:我加入
Set interval = New CInterval
Set interAll(0) = interval
你能向我解释这里到底发生了什么,这样我就不会再犯同样的错误修复了这个问题?
嘘,千万不要忘了给予好评,你发现的有用的意见,并接受你找到最有用的答案! (它不一定是我的!) – 2012-03-29 22:18:46