Team Fly |
Page 49
Dim strValue As String |
You must also add Imports Microsoft.Win32 up there at the top of the code window where all those other Imports are. The Microsoft.Win32 namespace contains the Registry-access functions, such as the OpenSubKey method that you need in this example.
Press F5 to run this example, and click the button. If your Registry contains the same value for this key as my Registry contains, you should see a result similar to this:
Mozilla/4.2 (compatible; MSIE 5.0; Win32)
Note that the complete name (path) of the entire Registry entry is divided into three different locations in the example code (they are in boldface): first the primary key, CurrentUser, then the path of subkeys, and finally the actual specific "name": objOpenedKey.GetValue("User Agent").
The RegistryKey class includes a group of methods you can use to manage and write to the Registry. These methods include Close, CreateSubKey, DeleteSubKey, DeleteSubKeyTree, DeleteValue, Get-SubKeyNames, GetType, GetValue, GetValueNames, OpenSubKey, and SetValue.
In VB6 and previous versions, you would generate a random number between 1 and 12 like this:
X = Int(Rnd * 12 + 1)
Or to get a random number between 0 and 12, you would use this code:
X = Int(Rnd * 13)
You used the Rnd and Randomize functions.
Team Fly |