Post

 Resources 

Console

Custom Resource Files Using Property Bags


Storing And Extracting Data From A Property Bag



To do anything involving a property bag, you need to first create a property bag object. The following code creates a new instance of a property bag, with the name objBag.

  1. Dim objBag As New PropertyBag

Not hard, huh? The property bag is part of the Visual Basic IDE so you don't even need a reference to it.
As with all instances of object, always remember to destroy the object, once you're done with it.

  1. Set objBag = Nothing

Doing so prevents those nasty memory leaks. But we don't want to destroy our property bag object just yet - we need to use it first!

Storing data in our property bag would be done like so:

  1. objBag.WriteProperty [Name ID], [Value], [Default Value]
  2. ' Example:
  3. objBag.WriteProperty "Str", "A string"

Here we're storing the string "A string" in the property bag using the string "Str" to tag it. We use that tag when we will extract data from the property bag. Here is how to read the written value.

  1. objBag.ReadProperty [Name ID], [Default Value]
  2. ' Example:
  3. Dim Str as String
  4. Str = objBag.ReadProperty "Str", "There is no value stored in the property bag"

Notice that you would store the property bag data in incompatible varible type without getting a compile-error, but first getting an error at run-time.




Next: Saving And Reading A Property Bag From Disk | 1 | 2 | 3 | 4 | 5

1 comment

Tutorial Console

Tutorial by:

Anders Nissen


Date: 2004 Oct 11


Navigate



1 comment

Latest comment


by: Eric Coleman

Very nice tutorial! I always thought the property bag was for custom controls only. This looks like a nice replacement for .ini files.

Post a Comment


Printer Friendly



Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.
There have been 17 visitors within the last 20 minutes
RSS News Feed