vbSaveSetting Command

Purpose

Saves or creates an application entry in the Windows registry entry using a VB compatible registry command.

Syntax

vbSaveSetting appName$, [section$], key$, value

Description

This VB compatible command saves a value under the key setting in the registry. The registry stores data in a hierarchically structured tree. Each node in the tree is called a key. Each key can contain both subkeys and data entries called values.

Visual Basic applications are required to store their registry settings under the entry called HKEY_CURRENT_USER\Software\VB and VBA Program Settings\appName\ section.

The vbGetSetting, vbGetSettingType, vbSaveSetting, vbDeleteSetting functions take appName and section as parameters to access the required entry in the HKEY_CURRENT_USER\Software\VB and VBA Program Settings\ registry key.

The vbSaveSetting command syntax has these arguments:

appName - Required. String expression containing the name of the application or project whose key setting is requested. May include section in GFA-BASIC 32.

section - Optional. String expression containing the name of the section where the key setting is found.

key - Required. String expression containing the name of the key setting to return.

value - Expression containing the value that key is being set to.

vbSaveSetting saves data always in the string (REG_SZ) format.

Example

vbSaveSetting "MyApp", "Startup", "Top", 75

vbSaveSetting "MyApp", "Startup", "Left", 50

Debug vbGetSetting("MyApp", "Startup", "Left", , 25)

vbDeleteSetting "MyApp", "Startup"

vbDeleteSetting "MyApp"

Remarks

It is possible to use the vbSaveSetting statement to create nested levels of keys and values in the Registry. This behavior is desirable in some cases.

For example, when receiving the location of a SYSTEM.MDA file, the Access engine expects the SystemDB value to exist in a subkey of Engines\Jet, like this:

HKEY_CURRENT_USER
\Software
\VB and VBA Program Settings
\MyApp
\Engines
\Jet
SystemDB = c:\access\system.mda

You can create nested levels in the Registry by using this syntax:

SaveSetting "TestApp", "Test2\Test3", "TestVal", "TestSetting"

This will create a section of the Registry that looks like:

HKEY_CURRENT_USER
\Software
\VB and VBA Program Settings
\TestApp
\Test2
\Test3
TestVal = TestSetting

To retrieve values stored in the Registry like this, use the same syntax with the vbGetSetting function. Some restrictions are inherited when creating nested keys with vbSaveSetting.

vbDeleteSetting does not work in the same fashion as they do with non-nested keys.

See Also

vbDeleteSetting, vbGetSetting, vbGetSettingType, vbDeleteSetting, GetSetting, GetSettingType, SaveSetting, DeleteSetting, CreateRegKey, OpenRegKey, CloseRegKey, GetRegVal, GetRegValName, GetRegValType, GetRegValNameCount, GetRegSubKey, GetRegSubKeyCount

{Created by Sjouke Hamstra; Last updated: 25/10/2014 by James Gaite}