You mean you want to take 4 arrays, with any number of values, and put them all into one array wit no repeating values?
The brute force method for this would be:
Code:
'create a new array
Dim endArray, cnt
'count maximum number of elements we might have
cnt = UBound(a) + 1 + UBound(b) + 1 + UBound(c) + 1 + UBound(d)
'redimension the array to hold that max number
ReDim endArray(cnt)
'define a function that accepts a number, checks if it is in the endArray, and adds it if it isn't (returns true) or throws it away if it's already in there (returns false)
Function AddToArray(aValue)
Dim i
'assume we will be adding it
AddToArray = True
'loop through the array
For i = 0 to UBound(endArray)
'check if the current value is equal to the passed value, if so we won't be adding the passed value
If endArray(i) = aValue Then AddToArray = False
'check if we have hit an empty array cell
If endArray(i) = "" Then Exit For
Next
'Now that we have exited, if AddToArray is still True, set the value to the last value of i
If AddToArray = True Then endArray(i) = aValue
'The value of AddToArray will automatically be passed back
End Function
'Loop through all four arrays, attempting to add the values. Count how many we actually add.
cnt = 0
Dim j
For j = 0 to UBound(a)
If AddToArray(a(j)) = True Then cnt = cnt + 1
Next
For j = 0 to UBound(b)
If AddToArray(b(j)) = True Then cnt = cnt + 1
Next
For j = 0 to UBound(c)
If AddToArray(c(j)) = True Then cnt = cnt + 1
Next
For j = 0 to UBound(d)
If AddToArray(d(j)) = True Then cnt = cnt + 1
Next
'cnt now holds the number of unique items we have
'so lets redim endArray by cnt-1
ReDim Preserve endArray(cnt-1)
This was written on the fly more to show the principle than to be workable. I'm rather tired so it may have some errors in it.
Another method would be to create a link list node object. Basically it would have the following functionality:
1) Add(aValue) - the node would check it's own value, if aValue is differant it would then check if it has a child node
- if the child node is null, it would create a child niode and give it that value
- if the child node is not null it would simply call it's childs Add(aValue) function
2) Count - if child was null it would return 1, if child is not null it would return 1 + child.Count
3) toArray(arr) - if the array wasn't initialized then the node (first one) would call it's own count function, redim the array
each node would set it's value: arr(UBound(arr)-me.Count) = myValue
it would then return Child.toArray(arr) so that each child could add their value
Anyways, to tired to write that one up, not sure if it would be fasterm, but it would ne niftier
01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website