This class is designed to store information about a single program to a single location in the Windows registry. Typically it is used to store program-specific run-time settings or switches such as form locations, or most-recently-used menu items.
Procedure Name | Type | Description |
(Declarations) | Declarations | Declarations and private variables for the CProgramSettings class. |
MainBranch | Property | Get the MainBranch property (defaults to "SOFTWARE"). |
Program | Property | Get the name of the current program for which settings are saved. |
RegBase | Property | Get the "base" registry entry (for example, each company's products might use the company name as the registry base). |
RootKey | Property | Get the RootKey used for the registry entries. |
Section | Property | Get the section of the registry to use to store the value in, within the RegBase and Product section (default value is "Settings"). You can specify a subkey by using a backslash as part of the value, e.g. "Settings\Forms\Positions". |
Class_Initialize | Initialize | Set initial values to defaults which may be overridden with property settings. |
ReadEntry | Method | Read a string value from the location in the registry specified by the class properties (Hive, MainBranch, RegBase, and Program). |
WriteEntry | Method | Write a string entry into the registry at the location specified by the class properties (Hive, MainBranch, RegBase, and Program). |
GetKeyValue | Private | Retrieve the specified key value. |
SetKeyValue | Private | Set a registry value. Will create key if it doesn't exist. |
' Example of CProgramSettings ' ' To try this example, do the following: ' 1. Create a new form ' 2. Create a command button 'cmdSetTime' ' 3. Create a command button 'cmdReadTime' ' 4. Paste all the code from this example to the new form's module. ' 5. Run the form Private mProgramSettings As CProgramSettings Private Sub cmdSetTime_Click() If mProgramSettings Is Nothing Then CreateProgramSettings End If ' Write an entry to the registry mProgramSettings.WriteEntry "Time", "Current Time: " & Now End Sub Private Sub cmdReadTime_Click() Dim strEntry As String If mProgramSettings Is Nothing Then CreateProgramSettings End If ' Read an entry from the registry strEntry = mProgramSettings.ReadEntry("Time", "Time not entered yet") Debug.Print strEntry End Sub Private Sub CreateProgramSettings() Set mProgramSettings = New CProgramSettings ' Set property settings to determine where the settings will be saved. ' In this example, the settings to into the same location used by the VBA/VB6 SaveSetting/GetSettings routines. ' This could be your company name, or the name of another known company such as "Microsoft" With mProgramSettings .RootKey = psrHKEY_LOCAL_MACHINE .MainBranch = "SOFTWARE" .RegBase = "FMS" .Program = "Test CProgramSettings" .Section = "Settings" End With End Sub Private Sub Form_Load() Me.cmdReadTime.Caption = "ReadTime" Me.cmdSetTime.Caption = "SetTime" End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP