SaveSetting Procedure


SaveSetting Procedure

Class

Microsoft.VisualBasic.Interaction

Syntax

     SaveSetting(appname, section, key, setting) 


appname (required; String)

The name of the application branch to be updated.


section (required; String)

The name of the application's subkey to be updated. This can be a single key or a relative registry path, with path components separated by backslashes.


key (required; String)

The name of the value entry to update.


setting (required; String)

The value to assign to the specified key value entry.

Description

The SaveSetting procedure creates or updates a single value in a specified section of your application's entry in the HKEY_CURRENT_USER\Software\VB and VBA ProgramSettings\ branch of the registry.

Usage at a Glance

  • The function writes a value within the KEY_CURRENT_USER\Software\VB and VBA ProgramSettings section of the registry.

  • If the appname, section, or key enTRies are not found in the registry, they are automatically created.

  • section is a relative path (similar to that used to describe the directories on a hard drive) used to navigate from the application key to the subkey to be updated. For example, to update the value entry named TestKey in the registry key HKEY_CURRENT_USER\Software\VB and VBA ProgramSettings\RegTester\BranchOne\BranchTwo, you would use:

         SaveSetting("RegTester", "BranchOne\BranchTwo", "TestKey", "test") 

  • Although the registry supports multiple data types, the GetSetting function only supports string values. All settings are written to the registry as REG_SZ entries.

  • If the setting cannot be saved, a runtime error occurs.

  • Since SaveSetting saves data on a per-user basis, it should not be used to save configuration settings that apply to all users, such as hardware configuration values.

  • You cannot use SaveSetting to update entries from registry keys that are not subkeys of HKEY_CURRENT_USER\Software\VB and VBA ProgramSettings.

  • SaveSetting does not allow you to write to the default value of a registry key. Attempting to do so produces a runtime error. This isn't a serious limitation, since the other Visual Basic "Settings" functions do not allow you to retrieve the default value of a registry key.

  • The .NET Framework includes registry-related features that provide more flexibility than the VB "Settings" functions. These features are found in the Registry and RegistryKey classes of the Microsoft.Win32 namespace.

Version Differences

Visual Basic 2005 includes several new features that let you manage the settings used by an application. Although they are not compatible with the older VB "Settings" functions, they provide a richer set of features. These features are located in the My.Settings object. The My.Computer.Registry object also provides access to convenient registry-related features.

See Also

DeleteSetting Procedure, GetAllSettings Function, GetSetting Function




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net