Is item read only?
item does not change. Is this correct ?Code:For Each item In Dat1 If InStr(item, ". ") > 0 Then Else item = "DELETE" End If Next
Is item read only?
item does not change. Is this correct ?Code:For Each item In Dat1 If InStr(item, ". ") > 0 Then Else item = "DELETE" End If Next
I've never used "For Each" with array so just tested. It works for me. Array element value is changed.
How do you know it did not change?
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
I added a watch to Dat1 and also printed it to the immediate window.
Yes, 'item' changed in the loop but the array did not.
Okay, I expanded my test. Confirmed item object variable is changed but array element is not.
AFAIK, only way to change content of array element is to address it with index references. As in: Dat1(x) = "DELETE".
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
That's what I did June, but was surprised it didn't change the array.
Thanks for confirming.
Are you watching the wrong item? Remember that arrays are zero based, unless you explicitly alter the base number.
I would not use item as a variable because it is a property name (e.g. Item(3) ).
This is for Excel vba but I doubt that matters much. More than you'd want to know about arrays.
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
How are Dat1 dimmed? Item? Can you post the code in broader context?
I don't know exactly what the purpose of your post is, whether to satisfy curiosity or to get results, but here's how to get results:
and the Immediate window:Code:Public Function ta() Dim dat1(3) As String, i As Integer dat1(0) = "dog. " dat1(1) = "cat" dat1(2) = "pig." dat1(3) = "Mon. ster" Dim itm As Variant For i = 0 To UBound(dat1) If InStr(dat1(i), ". ") > 0 Then Else dat1(i) = "Delete" End If Next For Each itm In dat1 Debug.Print itm Next End Function
call ta
dog.
Delete
Delete
Mon. ster
Middle, your code does not change array because it does not reference array element by index. So don't know what you mean by "That's what I did"
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.