Link to home
Start Free TrialLog in
Avatar of rbend
rbendFlag for United States of America

asked on

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.
Avatar of brandonb
brandonb

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..

www.cyd.liu.se/~freqv416/clsRegistry.cls

Tell me where you want to read and I can give you the source code for it.
Avatar of rbend

ASKER

VB Master:
I want to Read From and Write To:
HKEY_CURRENT_USER\Software\Astound\Astound\6.0\Settings
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?
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")
ASKER CERTIFIED SOLUTION
Avatar of Vbmaster
Vbmaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rbend

ASKER

Excellent Explaination.
Works Great.
Thanks.