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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search in an array

Status
Not open for further replies.

zrazzaq

MIS
Apr 13, 2005
102
US
Hi:
I was wondering is there a function to search inside of an array for example:
if I have an acct with duplicate categories I want the array to have one category not to be filled with duplicates.
For example:
Acct 1
Categories 2,2,2,3,4,5,6,6,6,
I want the array just to have
2,3,4,5,6
Can this be done
Thanks
Zishan
 
You can iterate through the array but that's not very efficient. Have you considered a collection?
Code:
Dim myArray() As Integer
Dim myCol As Collection
Set myCol = New Collection


On Error Resume Next
For n = 0 To CategoryCount
   myCol.Add Category(n), "X" & Category(n)
   If Err.Number = 0 Then
      Redim Preserve myArray(myCol.Count)
      myArray(myCol.Count) = Category(n)
   End If
   Err.Clear
Next n
Set myCol = Nothing
This way you insert only unique values into the array.
 
If your account ([acct 1].categories) information is in a table, then you can
1. create a Select query with the query's Unique Values property set to Yes;

2. open a recordset based on the query;

3. use the GetRows function to create an array based on the recordset.

Cheers,
Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top