I have a custom class and a custom collection associated with it. For the class object I have a "Asset Type" property which changes fro various instances of the object. Is there a way to find all the unique values associated with that property within the collection?
I assume at a bare minimal I can loop through all the objects in the collection and add the property values to an array of strings and then run a FindUniqueValues on that hash tag and save the revised string to a new array (See Below). However I was also wondering if there was a different way. And/or can I create that property itself in my custom collection (i.e. if clsAsset is the object, and clsPortfolio is the collection, can I create a custom property for the clsPortfolio called "AssetTypes" and perform a Count or FindUniqueValues Method on it such that Porftfolio.AssetTypes.Count returns the value I want.
'*******
Sub Test()
Dim tmparr1 () as String
Dim tmparr2 () as String
Dim tmp1 as String
tmp1 = ""
For each asset in portfolio
tmp = tmp & "|" & Asset.AssetType
Next
tmparr1 = Split (tmp, "|")
tmparr2 = FindUniqueValues(tmparr1)
End Sub
'**********
Private Function FindUniqueValues(arr as String)
Dim cUnique As Collection
Set cUnique = New Collection
Dim arr () as String
i = 0
For Each vNum In cUnique
VNum.Add (VNum,0)
Next vNum
For Each vNum In cUnique
arr(i) = vNum
Next vNum
FindUniqueValues = arr
End Sub
**************
Thanks
I assume at a bare minimal I can loop through all the objects in the collection and add the property values to an array of strings and then run a FindUniqueValues on that hash tag and save the revised string to a new array (See Below). However I was also wondering if there was a different way. And/or can I create that property itself in my custom collection (i.e. if clsAsset is the object, and clsPortfolio is the collection, can I create a custom property for the clsPortfolio called "AssetTypes" and perform a Count or FindUniqueValues Method on it such that Porftfolio.AssetTypes.Count returns the value I want.
'*******
Sub Test()
Dim tmparr1 () as String
Dim tmparr2 () as String
Dim tmp1 as String
tmp1 = ""
For each asset in portfolio
tmp = tmp & "|" & Asset.AssetType
Next
tmparr1 = Split (tmp, "|")
tmparr2 = FindUniqueValues(tmparr1)
End Sub
'**********
Private Function FindUniqueValues(arr as String)
Dim cUnique As Collection
Set cUnique = New Collection
Dim arr () as String
i = 0
For Each vNum In cUnique
VNum.Add (VNum,0)
Next vNum
For Each vNum In cUnique
arr(i) = vNum
Next vNum
FindUniqueValues = arr
End Sub
**************
Thanks