G
Guest
I'm finding that arrays in collections seem to be read-only - their element
values can't be changed. I need to get a sanity check on this please. I wrote
the following little routine to test this out, and to understand better
whether the array itself was put in the collection or just a pointer to the
original array entity (not as clear as with objects, and not addressed in
Help).
Public Sub dummy()
Dim lCollection As New Collection
Dim lArray(1 To 2) As String
lArray(1) = "a"
lArray(2) = "b"
lCollection.Add lArray
lCollection(1)(1) = "c" 'doesn't change value in Collection or
Array
lArray(1) = "d" 'only changes value in Array, not
Collection
End Sub
As you can see from above, if I try to change the value of the array element
in the collection, nothing actually changes; the original "a" value remains.
No error is reported, so I'm not doing anything obviously illegal. Because I
can read the value, my assumption is that I am addressing the element
correctly. If I change the original array, the value in the array changes to
"d", but the value as addressed by the collection remains "a".
I am using a relatively old version of Access (2000, I believe). If this is
old behavior that has changed, please let me know.
Has anyone dealt with this? I'd hate to have to create a class simply to
replace the array so that this behavior would work as expected, but will if
that's the only workaround. (I don't want to remove and replace the array;
hard to get it back in the same position in the collection.)
Thanks,
BnB
values can't be changed. I need to get a sanity check on this please. I wrote
the following little routine to test this out, and to understand better
whether the array itself was put in the collection or just a pointer to the
original array entity (not as clear as with objects, and not addressed in
Help).
Public Sub dummy()
Dim lCollection As New Collection
Dim lArray(1 To 2) As String
lArray(1) = "a"
lArray(2) = "b"
lCollection.Add lArray
lCollection(1)(1) = "c" 'doesn't change value in Collection or
Array
lArray(1) = "d" 'only changes value in Array, not
Collection
End Sub
As you can see from above, if I try to change the value of the array element
in the collection, nothing actually changes; the original "a" value remains.
No error is reported, so I'm not doing anything obviously illegal. Because I
can read the value, my assumption is that I am addressing the element
correctly. If I change the original array, the value in the array changes to
"d", but the value as addressed by the collection remains "a".
I am using a relatively old version of Access (2000, I believe). If this is
old behavior that has changed, please let me know.
Has anyone dealt with this? I'd hate to have to create a class simply to
replace the array so that this behavior would work as expected, but will if
that's the only workaround. (I don't want to remove and replace the array;
hard to get it back in the same position in the collection.)
Thanks,
BnB