rbend
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.
Registry level should be at least 2 down.
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.
www.cyd.liu.se/~freqv416/clsRegistry.cls
Tell me where you want to read and I can give you the source code for it.
ASKER
VB Master:
I want to Read From and Write To:
HKEY_CURRENT_USER\Software \Astound\A stound\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?
I want to Read From and Write To:
HKEY_CURRENT_USER\Software
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\Softwar e\Astound\ Astound\6. 0\Settings \". This is done with this code
Call Registry.CreateNewKey(HKEY _CURRENT_U SER, "Software\Astound\Astound\ 6.0\Settin gs")
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_US ER, "Software\Astound\Astound\ 6.0\Settin gs", "TestString", "ValueHere", REG_SZ)
Me.Caption = Registry.SetKeyValue(HKEY_ CURRENT_US ER, "Software\Astound\Astound\ 6.0\Settin gs", "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_C URRENT_USE R, "Software\Astound\Astound\ 6.0\Settin gs", "TestString")
Me.Caption = Registry.QueryValue(HKEY_C URRENT_USE R, "Software\Astound\Astound\ 6.0\Settin gs", "TestValue")
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\Softwar
Call Registry.CreateNewKey(HKEY
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_
Me.Caption = Registry.SetKeyValue(HKEY_
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_C
Me.Caption = Registry.QueryValue(HKEY_C
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent Explaination.
Works Great.
Thanks.
Works Great.
Thanks.
' 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"