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.
rbendAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brandonbCommented:
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"

0
VbmasterCommented:
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.
0
rbendAuthor Commented:
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?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

VbmasterCommented:
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")
0
VbmasterCommented:
Ouch *typos* in my last comment.. It should be

Public Registry As New clsRegistry

and

Private Registry as New clsRegistry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rbendAuthor Commented:
Excellent Explaination.
Works Great.
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.