PRB: VB Registry Functions Are Limited with Nested Settings

Last reviewed: April 11, 1996
Article ID: Q149038
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic for Windows, 16-bit and 32-bit, version 4.0

SUMMARY

The SaveSetting statement and GetSetting function in Visual Basic 4.0 for Windows are used to create and retrieve information from nested levels in the Registry. However, the related DeleteSetting statement does not handle these nested settings. The GetAllSettings function also has this limitation.

SYMPTOMS

Error 5 - Invalid Procedure Call appears when the DeleteSetting is attempted.

STATUS

This behavior is by design. The ability to create and retrieve values from nested levels in the registry was a fortunate byproduct of the design of the set and get functions, and this wasn't extended to include all of the related registry functions.

WORKAROUND

Use more than one DeleteSetting statement to remove sections of the nested keys before removing the top level key, rather than attempting to remove the top key in isolation.

For example, in the following, do not use:

   DeleteSetting "Test1"

Instead, use the following two lines of code to remove the Test1 key and its subkeys:

   DeleteSetting "Test1\Test2"
   DeleteSetting "Test1"

To enable all possible functionality, you can use the Registry API functions to perform any desired operation manually.

For more information on the Registry API functions, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q145679
   TITLE     : How to Use the Registry API to Save and Retrieve Setting

MORE INFORMATION

Steps to reproduce problem

  1. Start Visual Basic 4.0, 32-bit version. Form1 is created by default. Place two command buttons on the form. Add the following code to Form1:

       Private Sub Command1_Click()
           SaveSetting "Test1", "Test2\Test3", "TestKey", "TestValue"
       End Sub
    
       Private Sub Command2_Click()
           DeleteSetting "Test1"
       End Sub
    
    

  2. On the Run menu, choose Start, or press F5 to begin the application. Choose Command1 to add the nested keys to the registry. Open the Registry Editor and confirm that the information has been correctly added under the key HKEY_CURRENT_USER\Software\VB and VBA Program Settings.

  3. Return to the running application and choose Command2. VB will raise error 5 - Invalid Procedure Call. To view the workaround, stop the program and replace the single call to DeleteSetting with the two calls listed in the Workaround section above. Rerun the program and choose the second command button again. Use the Registry Editor to see that the keys have been removed correctly.


KBCategory: kbprg
KBSubcategory: PrgOther
Additional reference words: 4.00 vb4win vb4all



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 11, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.