Getting started

The classes

There are four classes to get familar with when using the EasyReg component. They all map to the structures in the system registry:

The only class which can be created is the RegNode class. This is always the class you start with.
From the RegNode class you can the work your way down the registry structures, querying for attached values and the sub-nodes attached to the current node.

You use the Set method in the RegNode class to point to a specific reistry key. This will initialize the class and you will be able to query the node for subnodes and values.

The RegNodes and RegValues classes are collection classes. They are handed to the caller when the Nodes and Values methods are called on the RegNode class.

Finally the RegValue class represents an actual registry value. It has two properties, Name and Value. The Name property, naturally, returns the name of the value, while the Value property returns the actual value. The value may be a number or a text, so the data type may vary.

You can use the collection classes, RegNodes and RegValues, to add and delete registry entries. Using the Add and Remove methods it is possible to build your own registry structures.

An example

A typical example for a EasyReg session:


Dim node As New RegNode
Dim value As RegValue

    Call node.Set(HKEY_CURRENT_USER, "SOFTWARE\Baan\BaanConfiguration")
    Set value = node.Values("MediaPath")
    Debug.Print value.Name & ": " & value.Value
    Set value = Nothing
    Set node = Nothing

This sample uses the new keyword to create a new RegNode class. It is also possible to use the CreateObject statement is Visual Basic.
The new RegNode class is then initialized and set to the "HKEY_CURRENT_USER\SOFTWARE\Baan\BaanConfiguration" registry key. From there we locate the "MediaPath" registry value and print out the value.

Performance

When working in a scripting language, such as MS Visual Basic, you always need to consider performance as an important factor of application development. This is especially true when working with collections.

In short, you should not do the following:


Dim node As New RegNode

    Call node.Set(HKEY_CURRENT_USER, "SOFTWARE\Baan\BaanConfiguration")
    Debug.Print node.Nodes("Display").Values("PosX").value
    Debug.Print node.Nodes("Display").Values("PosY").value
    Debug.Print node.Nodes("Display").Values("SizeX").value
    Debug.Print node.Nodes("Display").Values("SizeY").value
    Set subnode = Nothing
    Set node = Nothing

but rather write...


Dim node As New RegNode
Dim subnode As RegNode
Dim values As RegValues

    Call node.Set(HKEY_CURRENT_USER, "SOFTWARE\Baan\BaanConfiguration")
    Set subnode = node.Nodes("Display")
    Set values = node.Values
    Debug.Print values("PosX").value
    Debug.Print values("PosY").value
    Debug.Print values("SizeX").value
    Debug.Print values("SizeY").value
    Set values = Nothing
    Set subnode = Nothing
    Set node = Nothing

because the latter will only make one reference to each of the collection objects, while the first sample would query and recreate the entire collection each time a value is looked up. Needless to say, that only creating the collections once results in much faster execution.