|
-
Aug 26th, 2003, 04:43 PM
#1
Thread Starter
Frenzied Member
How can you add only unique items to an array?
-
Aug 26th, 2003, 04:47 PM
#2
There are a few methods to do this. Do a 'search' using unique array as the keywords.
-
Aug 26th, 2003, 05:27 PM
#3
Thread Starter
Frenzied Member
cant seem to find it anywhere
-
Aug 26th, 2003, 05:39 PM
#4
Your array would need to be sorted, then before attempting to add a new item, do a binary search of the array. If the item is not found, add it to the array and re-sort the array ready for the next item.
A bit of mucking round, but it's the only way I know how to do it, and if you pick the right sorting algorithm there's not too much overhead. Of course it depends on the type and volume of data you're storing.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Aug 26th, 2003, 05:45 PM
#5
Originally posted by VaxoP
cant seem to find it anywhere
There were like 140 hits, some of them demonstrated ways to load
an Array with unique numbers - for example.
-
Aug 26th, 2003, 06:41 PM
#6
Thread Starter
Frenzied Member
but none with strnigs
-
Aug 26th, 2003, 06:54 PM
#7
Could you not just loop thru the Array to check that the item does/dosn't exist?
In any event, please be more specific as to what you want/need to acheive 
Does the Array already exist with (string) data, and you want to add if not present?
Do you want to create a dynamic array of unique (string) data?
etc....
Bruce.
-
Aug 26th, 2003, 07:52 PM
#8
Hyperactive Member
the easiest way would be to replace the array with a collection. you can't have duplicate keys in a collection.
-
Aug 26th, 2003, 09:03 PM
#9
Thread Starter
Frenzied Member
how can you set it as a collection, and how can you work with it?
-
Aug 26th, 2003, 09:34 PM
#10
Hyperactive Member
simple
VB Code:
'to create the collection
dim col as collection
set col = new collection
'for adding items
col.add item, key
'for retreiving items
col.item(key) or col(key)
'for removing items
col.remove key
'to retrieve the count
col.count
'to clear the collection
set col = new collection
'to release the memory held by the collection
set col = nothing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|