Re: Best way to "filter" an array

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Elt must be declared as Variant to be used in a For Each loop
So you may just add:
Dim Elt
or
Dim Elt As Variant

HTH
Cordially
Pascal

"39N 95W" <gkammerer38@xxxxxxxxxxx> a écrit dans le message de news:
127907go7pcnsd7@xxxxxxxxxxxxxxxxxxxxx
Thanks for the quick reply! One question: what kind of object is Elt?
It's not a Keyword, is it? I realize it represents an element in the
array v, so should Elt be dimmed as a String if v contains String values?

-gk-

"papou" <cestpasbon@çanonplus> wrote in message
news:emJIfe0fGHA.2188@xxxxxxxxxxxxxxxxxxxxxxx
Hello
Option Base 1
Sub PutNondups()
Dim v(10)
Dim v2()
v(1) = "A"
v(2) = "B"
v(3) = "C"
v(4) = "A"
v(5) = "B"
v(6) = "A"
v(7) = "B"
v(8) = "A"
v(9) = "B"
v(10) = "C"

Dim Coll As New Collection

For Each Elt In v
On Error Resume Next
Coll.Add Elt, CStr(Elt)
If Err.Number = 0 Then
ReDim Preserve v2(1 To Coll.Count)
v2(Coll.Count) = Elt
End If
On Error GoTo 0
Next

For i = LBound(v2) To UBound(v2)
MsgBox v2(i)
Next i

End Sub

HTH
Cordially
Pascal

"39N 95W" <gkammerer38@xxxxxxxxxxx> a écrit dans le message de news:
1278uiskn3tq173@xxxxxxxxxxxxxxxxxxxxx
I have a 1-dimensional array whose members are single letter values, i.e.

V(1) = "A"
V(2) = "B"
V(3) = "C"
V(4) = "A"
V(5) = "B"
V(6) = "A"
V(7) = "B"
V(8) = "A"
V(9) = "B"
V(10) = "C"

I'd like to create a new array that is a filtered version of the array
above, where all duplicates are removed so that each member of the new
array is unique and not repeated, i.e.

A(1) = "A"
A(2) = "B"
A(3) = "C"

Any ideas on the best method? I can possibly visualize doing this with
some loops, but I'm having trouble getting my head around it. Any ideas
welcome.

Thanks!

-gk-


========================================================================
"The creative act is not the province of remote oracles or rarefied
geniuses but a transparent process that is open to everyone."
-Greg Kot in Wilco Learning How To Die-







.



Relevant Pages

  • Re: Best way to "filter" an array
    ... Dim v ... For Each Elt In v ... ReDim Preserve v2 ... I'd like to create a new array that is a filtered version of the array ...
    (microsoft.public.excel.programming)
  • Re: Best way to "filter" an array
    ... what kind of object is Elt? ... Dim v ... On Error GoTo 0 ... I'd like to create a new array that is a filtered version of the array ...
    (microsoft.public.excel.programming)
  • Re: Get last record of recordset that holds data
    ... Simplified as rs.GetRows will give a transposed array, ... but looks to me it is better to loop through columns in the ... Dim r As Long ... Dim lCycles As Long ...
    (microsoft.public.data.ado)
  • Re: Get last record of recordset that holds data
    ... no matter what the data is in the array. ... If the number of rows that have to be checked before encountering a non-null value is less than the number of columns, then yes, the collection of columns is the larger collection and should be in the outer loop. ... Dim r As Long ... Dim lCycles As Long ...
    (microsoft.public.data.ado)
  • Re: Scope of the arrays in Loops
    ... > Dim stAs Variant 'Integer ... > ' end of check for clash ... > In the do while loop i am storing the time values and later after the ... > array stand et. ...
    (microsoft.public.excel.programming)