Shoutbox

Settings in VB6 App Using Registry - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Settings in VB6 App Using Registry (/showthread.php?tid=50171)

Settings in VB6 App Using Registry by Salem on 09-07-2005 at 04:49 PM

Can anyone help me.

I wanna add a "Settings" feature to a VB app of mine. But would like the settings to be stored in the system registry? How can i rite data to and read data from the registry in Visual Basic 6? I have no idea of how to do this so if you could provide me with the required module(s) it'll be great.

Please

Thanks in advance, i know someone on these forums will be able to help me.
RileyM


RE: Settings in VB6 App Using Registry by Eljay on 09-07-2005 at 04:53 PM

http://www.mentalis.org/apilist/r.shtml

all the stuff beginning with Reg


RE: Settings in VB6 App Using Registry by Stigmata on 09-07-2005 at 04:55 PM

use a registry module...

some here:

http://pscode.com/vb/scripts/ShowCode.asp?txtCodeId=10479&lngWId=1
http://pscode.com/vb/scripts/ShowCode.asp?txtCodeId=36374&lngWId=1


Or generally :
http://pscode.com/vb/scripts/BrowseCategoryOrSear...fEntriesPerPage=10


RE: Settings in VB6 App Using Registry by Dempsey on 09-07-2005 at 04:56 PM

use can use

code:
GetSetting ( AppName As String,Section As String,Key As String, [Default]) As String


and 
code:
SaveSetting ( AppName As String,Section As String) As String


RE: Settings in VB6 App Using Registry by RaceProUK on 09-07-2005 at 05:19 PM

But with those you don't really have much control.
If you want more control, use RegOpenKey(), RegCreateKey(), RegQueryValueEx(), RegSetValueEx(), and RegCloseKey().


RE: RE: Settings in VB6 App Using Registry by Salem on 09-07-2005 at 05:40 PM

quote:
Originally posted by Dempsey
use can use
code:
GetSetting ( AppName As String,Section As String,Key As String, [Default]) As String


and 
code:
SaveSetting ( AppName As String,Section As String) As String




Wouldn't i need to declare anything if using this method?

quote:
Originally posted by raceprouk
But with those you don't really have much control.
If you want more control, use RegOpenKey(), RegCreateKey(), RegQueryValueEx(), RegSetValueEx(), and RegCloseKey().


What functionality do these ones provide that Dempsey's don't. I just want very basics for now.
RE: Settings in VB6 App Using Registry by Dempsey on 09-07-2005 at 05:45 PM

GetSetting and SaveSetting are ideal for basic saving and retrieving of user options.  ANd you don't need to decalre anything as they are built-in VB commands.


RE: RE: Settings in VB6 App Using Registry by Salem on 09-07-2005 at 06:17 PM

quote:
Originally posted by Dempsey
GetSetting and SaveSetting are ideal for basic saving and retrieving of user options.  ANd you don't need to decalre anything as they are built-in VB commands.


Oh thanks, that seems good enough for me. Can you give me a code example on how they are used.

Sorry, if im askin alot. I just can't find anything online, and this is the first time im trying it.

RileyM
RE: Settings in VB6 App Using Registry by Dempsey on 09-07-2005 at 07:23 PM

code:
SaveSetting ("MyAppName", "MySettingName", "MySettingValue")


GetSetting ("MyAppName", "MySettingName")



RE: Settings in VB6 App Using Registry by RaceProUK on 09-07-2005 at 07:34 PM

If you want help with the Reg*() functions, don't hesitate to ask. They're not hard to use once you get used to them ;)
For now though, Get/SaveSetting will do you fine ;)


RE: RE: Settings in VB6 App Using Registry by Salem on 09-07-2005 at 07:43 PM

quote:
Originally posted by Dempsey
code:
SaveSetting ("MyAppName", "MySettingName", "MySettingValue")


GetSetting ("MyAppName", "MySettingName")





Thanks just two more Q's
  1. If i say use GetSetting to retrive a setting in the registry, how would i put the value retrieved into a variable? eg, into a variable called SettingValue
  2. If i would like an installer to create default values for a MySettingName, where should this be created?
    [/list]


    Thanks

RE: Settings in VB6 App Using Registry by RaceProUK on 09-07-2005 at 07:56 PM

Dim value As Variant
value = GetSetting("MyAppName", "MySettingName")

And please don't double-post - edit.


RE: RE: Settings in VB6 App Using Registry by Salem on 09-07-2005 at 07:58 PM

quote:
Originally posted by raceprouk
Dim value As Variant
value = GetSetting("MyAppName", "MySettingName")

And please don't double-post - edit.


Thanks i thought i would be somethhing like that.

Sorry about the double post.

Do you know an answer to question 2?

quote:
2. If i would like an installer to create default values for a MySettingName, where should this be created?

Edit: Double post deleted
RE: Settings in VB6 App Using Registry by RaceProUK on 09-07-2005 at 08:00 PM

Just beware of using Variants - the lack of type checking can be the source of errors later.


RE: Settings in VB6 App Using Registry by Dempsey on 09-07-2005 at 08:02 PM

quote:
Originally posted by RileyM
Thanks just two more Q's
  1. If i say use GetSetting to retrive a setting in the registry, how would i put the value retrieved into a variable? eg, into a variable called SettingValue
  2. If i would like an installer to create default values for a MySettingName, where should this be created?
    [/list]

    Thanks
1.  You would use something like.....

code:
SaveSetting "MyAppName","Settings","SettingName","SettingValue")




2.  I assume you mean if you're using an insatller such as NSIS or Inno Setup, in which case the path is:
quote:
HKEY_CURRENT_USER\Software\VB and VBA Program Settings\MyAppName\Settings

RE: RE: Settings in VB6 App Using Registry by Salem on 09-07-2005 at 08:04 PM

quote:
Originally posted by Dempsey
quote:
Originally posted by RileyM
Thanks just two more Q's
  1. If i say use GetSetting to retrive a setting in the registry, how would i put the value retrieved into a variable? eg, into a variable called SettingValue
  2. If i would like an installer to create default values for a MySettingName, where should this be created?
    [/list]

    Thanks
2.  I assume you mean if you're using an insatller such as NSIS or Inno Setup, in which case the path is:
quote:
HKEY_CURRENT_USER\Software\VB and VBA Program Settings\MyAppName\Settings

Yes this is what i meant, Thanks again
RE: Settings in VB6 App Using Registry by Millenium_edition on 09-07-2005 at 08:08 PM

quote:
Originally posted by raceprouk
Just beware of using Variants - the lack of type checking can be the source of errors later.
even if you don't use the variants, type checking in VB is incredibly limited...
RE: Settings in VB6 App Using Registry by Salem on 09-08-2005 at 04:07 PM

quote:
SaveSetting ("MyAppName", "MySettingName", "MySettingValue")


GetSetting ("MyAppName", "MySettingName")
When typing the SaveSetting code, when i move i think im finished and i move to the next line i get the following messager

quote:
Comile Error:

Expected: =

What am i doing wrong?

My SaveSetting Code is a followed
code:
SaveSetting(app.ProductName, "LastVolLevel", SettingsLastVol)

app.productname is my application name
SettingsLastVol is the value from a Global variable that needs to be entered into the Value of that setting. I hope i explained myself properly.

Thanks in advance

RileyM
RE: Settings in VB6 App Using Registry by Dempsey on 09-08-2005 at 04:22 PM

remove the brackets and then it will work fine


RE: RE: Settings in VB6 App Using Registry by Salem on 09-08-2005 at 04:26 PM

quote:
Originally posted by Dempsey
remove the brackets and then it will work fine


Should i also remove the brackets from

code:
value = GetSetting("MyAppName", "MySettingName")

Coz im am getting the following Error

"Complie Error: Argument Not optional" with the GetSetting part highlighted
RE: Settings in VB6 App Using Registry by Dempsey on 09-08-2005 at 04:31 PM

No, you need the brackets on that line because you are setting the result of the function into a variable.

You are probably getting errors because you are only passing it two arguements and it needs three.

code:
value = GetSetting("MyAppName", ",Settings","MySettingName")

RE: RE: Settings in VB6 App Using Registry by Salem on 09-08-2005 at 04:35 PM

quote:
Originally posted by Dempsey
No, you need the brackets on that line because you are setting the result of the function into a variable.

You are probably getting errors because you are only passing it two arguements and it needs three.
code:
value = GetSetting("MyAppName", ",Settings","MySettingName")



So what does the middle argument mean? What is it for?
RE: Settings in VB6 App Using Registry by Dempsey on 09-08-2005 at 05:10 PM

its the keyname you can call it whatever you want, but it obviously has to be the same in both your SaveSetting and GetSetting calls.

If you are saving options then aveing it something like Settings or Options makes logical sense.


RE: RE: Settings in VB6 App Using Registry by Salem on 09-08-2005 at 05:13 PM

quote:
Originally posted by Dempsey
its the keyname you can call it whatever you want, but it obviously has to be the same in both your SaveSetting and GetSetting calls.

If you are saving options then aveing it something like Settings or Options makes logical sense.


I didn't use a keyname in the SaveSetting call? Should i, if so, should this also be the second argument?
RE: Settings in VB6 App Using Registry by Dempsey on 09-08-2005 at 05:20 PM

yes its the second arguement, 'Section'

[Image: attachment.php?pid=531687]


RE: Settings in VB6 App Using Registry by CookieRevised on 09-08-2005 at 05:20 PM

RileyM, please look in your help files...
Explaining everything about GetSetting/SaveSetting is too much. And explaining the registry API's is even much more to explain.

Put your cursor on "GetSetting" and/or "SaveSetting" in VB6 and press F1 to access the help files...

Or, in case you have an illegal version :rolleyes: you can also take a look at the msdn library which contains all the VB6 helpfiles. More specifically, the Visual Basic Document: Programmers Reference. There you'll find every command, statement, whatever you can use in VB6 with full detailed explanations (just as in the help files; heck, they are the helpfiles, but online).

eg:
SaveSetting
GetSetting
DeleteSetting
GetAllSettings


---------------

As for GetSetting/SaveSetting. This saves data to "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\*". But that registry path isn't much appreciated by many ("professional") people. If you can, don't use GetSetting/SaveSetting as they not only save data in a very obscure place, they also don't provide much flexibility. Use the registry API functions instead, but only if you know exactly what each function does and why and what the restrictions are etc. In other words, you need to know (almost) everything about the registry and its API's. This said, if you are making a private project (one which you aren't gonna distribute) you can do whatever you like of course.

---------------

Also, a very important note on the registry example modules/classes you'll find on the net for VB6. They all are roughly the same (no wonder, they all are copies from eachother without people even checking the API's and their funcionality and ins and outs!!!). They contain some errors and/or some minor glitches and don't always provide 100% compatibily with all Windows versions or even provide decent/correct functionality (yes, and I'm even speaking of the ones you'll find on sites like vbAccelerator, although they are correct for the most part, they often are very bloated... Codes you'll find on PSC are even worse and should never be taken as-is!)...

I say this because some time ago, I searched for some example registry module/class (because I was in a lazy mood). After finding out that everything you find on the net is a copy of eachother I began to wonder and studied the API's and registry and quickly came to the conclussion that all those sources can be optimized a lot and even contained some glitches (note: all this goes for many many... many example sources).


RE: RE: Settings in VB6 App Using Registry by Salem on 09-08-2005 at 05:28 PM

quote:
Originally posted by CookieRevised
RileyM, please look in your help files...
Explaining everything about GetSetting/SaveSetting is too much. And explaining the registry API's is even much more to explain.

Put your cursor on "GetSetting" and/or "SaveSetting" in VB6 and press F1...

Or, in case you have an illegal version :rolleyes: you can also take a look at the msdn library which contains all the VB6 helpfiles. More specifically, the Visual Basic Document: Programmers Reference. There you'll find every command, statement, whatever you can use in VB6 with full detailed explanations (just as in the help files; heck, they are the helpfiles, but online).

eg:
SaveSetting
GetSetting
DeleteSetting
GetAllSettings


---------------

As for GetSetting/SaveSetting. This saves data to "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\*". But that registry path isn't much appreciated by many ("professional") people. If you can, don't use GetSetting/SaveSetting as they not only save data in a very obscure place, they also don't provide much flexibility. Use the registry API functions instead, but only if you know exactly what each function does and why and what the restrictions are etc. In other words, you need to know (almost) everything about the registry and its API's. This said, if you are making a private project (one which you aren't gonna distribute) you can do whatever you like of course.

---------------

Also, a very important note on the registry example modules/classes you'll find on the net for VB6. They all are roughly the same (no wonder, they all are copies from eachother without people even checking the API's and their funcionality and ins and outs!!!). They contain some errors and/or some minor glitches and don't always provide 100% compatibily with all Windows versions (yes, and I'm even speaking of the ones you'll find on sites like vbAccelerator... Codes you'll find on PSC are even worse!)...

I say this because some time ago, I searched for some example registry module/class (because I was in a lazy mood). After finding out that everything you find on the net is a copy of eachother I began to wonder and studied the API's and registry and quickly came to the conclussion that all those sources can be optimized a lot and even contained some glitches (note: all this goes for many many... many example sources).


Thank-you for the suggestion, i will take a look at the VB Help (once i get arround to installing the MDSN documentaion, i do have the CDs i just ahven't bothered doing it yet).

Also sorry for asking so many questons regarding this, i have looked at the links provided earlier in this thread, but to be honest i didn't undertsand them at all, but the help i was given here did at least help with the very basics.

Thanks

RileyM