![]() |
Dictionary objet
Hi all,
I wish to use the Dictionary object but with some modifications as follows: At the "Add method" to have a third option to sum up the frequency of that "key". At the "Remove method" do remove the item if that third key above has frequency of 1, otherwise reduce that key by 1. Is this possible? or do I have to create my own class to accommodate the above? TIA Zwi, |
Dictionary objet
Zwi,
I don't think so, you will need to code it yourself. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Zwi" wrote in message ... Hi all, I wish to use the Dictionary object but with some modifications as follows: At the "Add method" to have a third option to sum up the frequency of that "key". At the "Remove method" do remove the item if that third key above has frequency of 1, otherwise reduce that key by 1. Is this possible? or do I have to create my own class to accommodate the above? TIA Zwi, |
Dictionary objet
Zwi wrote in message ...
I wish to use the Dictionary object but with some modifications as follows: At the "Add method" to have a third option to sum up the frequency of that "key". At the "Remove method" do remove the item if that third key above has frequency of 1, otherwise reduce that key by 1. Is this possible? or do I have to create my own class to accommodate the above? The Dictionary object is part of the Microsoft Scripting Runtime, which is a compiled DLL. You'd need access to the (presumably C++) source code to change its interface, all of which sounds like rather more work than your second option! I'd suggest you create, in fact, two new classes, one to extend the functionality of Dictionary, ReferenceCountedDictionary, say (!) and ReferenceCountedItem. So you might have (I'm typing this off the top of my head, no guarantees as to perfection!) Class ReferenceCountedDictionary: Private dict As Dictionary Public Sub Add(key, newobject) dim o as ReferenceCountedItem If dict.Exists(key) Then dict.Item(key).IncrementCount Else Set o = New ReferenceCountedItem set o.Obj = newobject End If End Sub Public Sub Remove(key) If dict.Exists(key) Then If dict.Item(key).Count = 1 Then dict.Remove key Else dict.Item(key).DecrementCount End If End If End Sub .... and Class ReferenceCountedItem: Public Count As Long ' you might prefer to use Private declarations and Public Obj As Object ' access them via Properties... Public Sub IncrementCount Count = Count + 1 End Sub Public Sub DecrementCount Count = Count - 1 End Sub Private SUb Class_Initialize Count=1 End Sub .... I hope that gives an idea of how you might accomplish it! |
All times are GMT +1. The time now is 11:26 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com