Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looping unique value form array list

Status
Not open for further replies.

2009luca

Programmer
Jul 27, 2013
222
IT
I just have MyArray filled with:
1111
1111
2222
3333
3333
3333
...
Ecc.
i need to looping a unique items form the array

For example
1111
2222
3333

How to?

 
One way is to use the Dictionary object. Loop through each array element, and use the Dictionary object's "Exists" method to only add unique values to the dictionary. Google will yield many samples.
 
Create a database table (in memory) of the data as rows (many examples around)
Use a query using FIRST OF in the query will yield only one instance of each number when you loop through the resulting query results.
 
Ted, if you read the thread linked by SaltyTheFrog you'll find that the OP does indeed get their array from a recordset.

It is currently unclear why they don't just do a SELECT DISTINCT
 
stromgm
Because I answered the original question on this form that did not mention a recordset.

I assumed he was wanting to find out how to do it with an array obtained by any method.
It should have given him the clue that if he already had it from recordset, then just apply a different "SQL" to the one he has.
 
>that did not mention a recordset

Sometimes important to read the whole thread ... ;-)

But if you were looking at it from the point of view of "how to do it with an array obtained by any method" I'm not sure that loading the ADO library just to eliminate duplicates is ideal. The dictionary solution mentioned by guitarzan would be my preferred approach - although I'd be tempted to stick with VB's built in Collection class instead.
 
Would this depend on the size of the file?
I do use a recordset method I described to extract unique values from a CSV file about 20mb in size.
It only take a few seconds with a recordset. I would think far faster than looping through the records.

I also had not thought of using SELECT DISTINCT!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top