Re: Weird PropertyBag problem, values won't change



"Andy DF" <nospam@xxxxxxxxxx> wrote in message
news:43d7426f$0$333$5fc30a8@xxxxxxxxxxxxxxx
> Ok, I know what's happening here:
>
> Everytime WriteProperty is called it appends a NEW property, with the
> specified name, EVEN IF IT ALREADY EXISTS!!
> And when ReadProperty is called, it just returns the first property
> with the specified name that it finds.
> Major bug!!!

This is not a bug, it is by design. Try this:

Private Sub Main()
Dim p As PropertyBag
Dim x As Long
Set p = New PropertyBag
For x = 1 To 5
p.WriteProperty "myprop", "value" & CStr(x)
Next
For x = 1 To 5
Debug.Print p.ReadProperty("myprop")
Next
Set p = Nothing
End Sub

It is an easy way to store a list in a propertybag. You can store another
property with the count of items added and then retrieve them all using the
same name. It looks like you are trying to use a property bag like a
collection or dictionary with the property name acting as the key to a
single item and that's just not how the object works. Maybe if you describe
what your real need is somebody can suggest a better way to accomplish it.


--
Reply to the group so all can participate
VB.Net: "Fool me once..."

.



Relevant Pages

  • Re: Module Data Storage
    ... please note that the multi-select listbox is not designed to store data. ... that person's hobbies from the list of all possible hobbies. ... Private Sub ClearHobbySelections() ... Dim rs As DAO.Recordset ...
    (microsoft.public.access.modulesdaovba)
  • Re: Overflow
    ... All that means is that you're trying to store a value in a variable whos ... Private Sub Form_Load ... Dim i As Integer ... The most common reason is.... ...
    (microsoft.public.vb.general.discussion)
  • Re: solution to Word 2007 BUG options.printbackground failure
    ... Here's a code sample to work around the bug: ... Private Sub OfficeUserName() ... 'Validate user name and ask for a correction if needed ... Dim dlgUserInfo As Dialog ...
    (microsoft.public.word.vba.general)
  • Re: Weird PropertyBag problem, values wont change
    ... I see your point but I can't help but it seeing it as a bug. ... > Private Sub Main ... > Dim p As PropertyBag ... > It is an easy way to store a list in a propertybag. ...
    (microsoft.public.vb.controls)
  • Re: Random Numbers with a twist
    ... Dim n As Single ... Store r ... Private Function GetRnd ... Private Sub Store ...
    (microsoft.public.vb.general.discussion)

Quantcast