
Duplicate keys allowed with VB PropertyBag object ???
Indeed this appear to be the solution that many of us have searched distant
lands for. How to save arrays and collections to the property bag. Most of
us end up creating counter that form part of the property name.
For i= 1 to 10
call propbag.Writeproperty("MyProperty" & Cstr(i), MyArray(i))
next i
but your revelation shows that the counter does not need to be par tof the
key
For i= 1 to 10
call propbag.Writeproperty("MyProperty" ,MyArray(i))
next i
This is revolutionary, and we salute you.
Shame VB is about to be pensioned off!
Quote:
> Bizarre! I've not used the PropertyBag outside
> of a UserControl, so I'd not noticed this.
> You can Debug.Print pb.Contents to see that
> there's two Item1 entries!
> It does appear that this is by design, however
> because the ReadProperty maintains a pointer
> such that the next "Item1" will be read.
> Sorry I can't fix this for you. Alternatives to
> using a PropertyBag would be the Dictionary
> or Collection objects.
> > Does anyone know how to avoid saving duplicate keys in VB's PropertyBag
> > object?
> > Eg
> > Dim pb as New PropertyBag
> > pb.WriteProperty "Item1" , 1
> > pb.WriteProperty "Item1" , 2 'This does not update
> the
> > value
> > debug.print pb.ReadProperty "Item1" 'returns 1
> > debug.print pb.ReadProperty "Item1" 'returns 2
> > Thanks
> > Saby