• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

How to write to and read from the Registry (98)

Please offer as little code as possible to write to and read from the Registry on a Win95/98 machine.
Registry level should be at least 2 down.
  • 3
  • 2
1 Solution
Got this straight out of the VB help.

' Variant to hold 2-dimensional array returned by GetSetting.
Dim MySettings As Variant
' Place some settings in the registry.
SaveSetting "MyApp","Startup", "Top", 75
SaveSetting "MyApp","Startup", "Left", 50

Debug.Print GetSetting(appname := "MyApp", section := "Startup", _
                       key := "Left", default := "25")

DeleteSetting "MyApp", "Startup"

Here's a class to implement real registry reading/writing..


Tell me where you want to read and I can give you the source code for it.
rbendAuthor Commented:
VB Master:
I want to Read From and Write To:
And I need to know how to put in a string and a value.
How do I add the CLASS you suggested to my app?
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

You add the class file in the menu Project -> Add Class Module -> the 'Existing' tab and choose the file there. This will import the class file into your existing project.

Now to be able to use the class you will need to create a variable referring to the class, for example if you need to use the registry everywhere in the program you can put

Public clsRegistry As New clsRegistry

in a module, or if you only need it inside a single form, you can put this code in the Declaration part of the form

Private clsRegistry as New clsRegistry

Now how to use the class..

First you need to create the key "HKEY_CURRENT_USER\Software\Astound\Astound\6.0\Settings\". This is done with this code

  Call Registry.CreateNewKey(HKEY_CURRENT_USER, "Software\Astound\Astound\6.0\Settings")

Now you can save for example a string value and a numerical value.. (REG_SZ means strings and REG_DWORD means double word that's C++ name for Long).

  Me.Caption = Registry.SetKeyValue(HKEY_CURRENT_USER, "Software\Astound\Astound\6.0\Settings", "TestString", "ValueHere", REG_SZ)

  Me.Caption = Registry.SetKeyValue(HKEY_CURRENT_USER, "Software\Astound\Astound\6.0\Settings", "TestValue", 100, REG_DWORD)

The return value is True if successful, False if not.

To get the value of the string or the numerical value you use code like this..

  Me.Caption = Registry.QueryValue(HKEY_CURRENT_USER, "Software\Astound\Astound\6.0\Settings", "TestString")

  Me.Caption = Registry.QueryValue(HKEY_CURRENT_USER, "Software\Astound\Astound\6.0\Settings", "TestValue")
Ouch *typos* in my last comment.. It should be

Public Registry As New clsRegistry


Private Registry as New clsRegistry
rbendAuthor Commented:
Excellent Explaination.
Works Great.

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now