Duplicate keys allowed with VB PropertyBag object ??? 
Author Message
 Duplicate keys allowed with VB PropertyBag object ???

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



Mon, 27 Oct 2003 00:02:24 GMT  
 Duplicate keys allowed with VB PropertyBag object ???
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.


Quote:
> 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



Mon, 27 Oct 2003 10:07:11 GMT  
 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



Tue, 28 Oct 2003 02:40:43 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Duplicate keys allowed with VB PropertyBag object ???

2. Duplicate keys allowed with VB PropertyBag object ???

3. VB & Access: duplicate inserts on unique key

4. Duplicate values not allowed

5. How do I allow duplicates, Please?

6. RESUBMISSION - persisting objects in ActiveX control propertybag

7. persisting objects in ActiveX control propertybag

8. Problem storing object in PropertyBag

9. VB5 PropertyBag object only working at design time

10. Using Propertybag object to carry data over network

11. persisting objects in ActiveX control propertybags

12. keyascii allow key use once

 

 
Powered by phpBB® Forum Software