GetAllSettings Function

   
GetAllSettings Function

Class

Microsoft.VisualBasic.Interaction

Syntax

 GetAllSettings(   appname   ,   section   ) 
appname (required; String)

Name of the application

section (required; String)

Relative path from appname to the key containing the settings to retrieve

Return Value

An object containing a two-dimensional array of strings

Description

Returns the registry value entries and their corresponding values for the application

Rules at a Glance

  • GetAllSettings works exclusively with the subkeys of HKEY_CURRENT_USER\ Software\VB and VBA Program Settings .

  • The elements in the first dimension of the array returned by GetAllSettings contain the value entry names .

  • The elements in the second dimension of the array returned by GetAllSettings contain the values for the respective value entries.

  • The two-dimensional array returned by GetAllSettings is based at 0 (as are all arrays) so the first value entry name is referenced using (0,0).

  • A call to GetAllSettings will return only the value entry names and data belonging to the final registry key specified by the section argument. If that key itself has one or more subkeys, their data will not be retrieved by the function.

  • If either appname or section do not exist, GetAllSettings will return an uninitialized Object.

Programming Tips and Gotchas

  • GetAllSettings is a function that was developed to retrieve data from initialization files in 16-bit environments and to retrieve data from the registry under Windows 9x and Windows NT. The language of the documentation, however, reflects the language of initialization files. The arguments labeled appname and section are in fact registry keys; the argument labeled key is in fact a registry value entry.

  • The built-in registry-manipulation functions allow you to create professional 32-bit applications that use the registry for holding application-specific data, in the same way that .INI files were used in the 16-bit environment. You can, for example, store information about the user 's desktop settings (i.e., the size and position for forms) the last time the program was run.

  • Because the built-in registry functions in VB only create string-type registry keys, GetSetting and GetAllSettings return string values. Therefore, before you use numeric values returned from the registry, you should explicitly convert the value to a numeric data type.

  • GetAllSettings , SaveSettings , and GetSetting allow you direct access to only a limited section of the windows registry, that being a special branch created for your application ( HKEY_CURRENT_USER\Software\VB and VBA Program Settings) . You cannot access or change other registry settings without using the Win32 API.

  • Use the code Application.ExecutablePath to pass your application's name to the GetAllSetting function.

  • Only those settings that were created using either the Win32 API or the SaveSetting function will be returned. In other words, a VB application does not have a registry entry unless you have created one explicitly.

  • If the key read by GetAllSettings has a default value, that value will not be retrieved by the function. If you want to store and retrieve default values, you must call the Win32 API directly.

  • Because GetAllSettings returns an uninitialized Object when either appname or section do not exist, if you subsequently try to perform a UBound or LBound function on the object, a "Type Mismatch" error will be generated. You can test the validity of the returned value, as follows :

     Dim MySettings(,) As String Dim intSettings As Integer ' Place some settings in the registry. SaveSetting("WindowsApplication6", "Startup", "Top", "75") SaveSetting("WindowsApplication6", "Startup", "Left", "50") ' Retrieve the settings. MySettings = GetAllSettings(appname:="WindowsApplication6", _      section:="Startup") If Not (MySettings Is Nothing) Then    For intSettings = 0 To UBound(MySettings, 1)       Console.WriteLine(MySettings(intSettings, 0))       Console.WriteLine(MySettings(intSettings, 1))    Next intSettings    DeleteSetting("WindowsApplication6", "Startup") else    MsgBox("No settings") End If 
  • Because GetAllSetting retrieves data from the user branch of the registry, and the physical file that forms the user branch of the registry may change (depending, of course, on who the user is and, in the case of Windows 9x systems, whether the system is configured to support multiple users), never assume that an application has already written data to the registry. In other words, even if you're sure that your application's installation routine or the application itself has successfully stored values in the registry, never assume that a particular value entry exists, and always be prepared to substitute a default value if it does not.

  • Rather than rely on the relatively underpowered registry-access functionality available in Visual Basic, we highly recommend that you instead use the Registry and RegistryKey classes available in the BCL's Microsoft.Win32 namespace.

See Also

DeleteSetting Procedure, GetSetting Function, SaveSetting Procedure

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

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