GetAllSettings Function

Named Arguments

Yes

Syntax

GetAllSettings(appname, section)


appname

Use: Required

Data Type: String

Name of the application.


section

Use: Required

Data Type: String

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

Return Value

A Variant 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_USERSoftwareVB 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 zero. Therefore, the first value entry name is referenced using (0,0).

  • A call to GetAllSettings returns 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 isn't retrieved by the function.

  • If an application has multiple nested subkeys, all their data can be retrieved by specifying the relative path from the application key to the desired key in the section parameter. For example, if SettingsCoordinates is the value of the section argument, the function attempts to retrieve all values from the subkey HKEY_CURRENT_USERSoftwareVB and VBA Program SettingsappnameSettingsCoordinates.

  • If appname or section doesn't exist, GetAllSettings returns an uninitialized Variant.

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 Win9x and WinNT. 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 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 is run.

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

  • GetAllSettings, SaveSettings, and GetSetting allow you direct access to a limited section of the windows registry, that being a special branch created for your application (HKEY_CURRENT_USERSoftwareVB and VBA Program Settingsyourappname). You can't access or change other registry settings without using the Win32 API.

  • Use the App object's EXEName property to pass your application's name to the GetAllSetting function.

  • All the registry-manipulation functions in VB work equally well with both Windows NT and Windows 95. The same, however, can't be said of the Win32 API calls required to return and change other registry settings.

  • Only those settings that are created using either the Win32 API or the SaveSettings function are returned. In other words, a VB application doesn't have a registry entry unless you create one explicitly.

  • If the key read by GetAllSettings has a default value, that value isn't 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 Variant when either appname or section doesn't exist, if you subsequently try to perform a UBound or LBound function on the variant, a Type Mismatch error is generated. You can test the validity of the returned variant using the IsEmpty function as follows:

    Dim vRegSettings As Variant
    Dim iSettings As Integer
        
    vRegSettings = GetAllSettings(appname:=App.EXEname, _
                                  section:="Startup")
    If Not IsEmpty(vRegSettings) Then
       For iSettings = LBound(vRegSettings, 1) To _
                       UBound(vRegSettings, 1)
          Debug.Print vRegSettings(iSettings, 0) & "; " _
                      & vRegSettings(iSettings, 1)
       Next iSettings
    End If

  • Because GetAllSettings 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 Win9x systems, whether or not 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 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 doesn't.

See Also

DeleteSetting Statement, GetSetting Function, SaveSetting Statement
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset