home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


We stored the MRU file name in a Registry section named “Settings” and gave that file name the key “Doc1”. When the program’s form first loads, then, we got the file name last stored there, if there was one, with GetSetting this way:

Private Sub Form_Load()
    Dim FileName As String
    FileName = GetSetting(App.Title, "Settings", "Doc1")

    If FileName <> "" Then
        Load mnuMRU(1)
        mnuMRU(1).Caption = FileName
        mnuMRU(1).Visible = True
    End If
End Sub

On the other hand, when the user opens a file, we store that file’s name in the Windows Registry this way so we can add it to the MRU menu item later:

Private Sub mnuOpen_Click()
    With dlgCommonDialog
        .DialogTitle = "Open"
        .CancelError = False
        .Filter = "All Files (*.*)[vbar]*.*"
        .ShowOpen
        If Len(.FileName) = 0 Then
            Exit Sub
        End If

        If GetSetting(App.Title, "Settings", "Doc1") = "" Then
            Load mnuMRU(1)
        End If
        mnuMRU(1).Caption = .FileName
        mnuMRU(1).Visible = True
        SaveSetting App.Title, "Settings", "Doc1", .FileName
    End With
End Sub

And that’s all there is to it—using SaveSetting and GetSetting, you can access the Windows Registry directly in a simple way.

Getting All Registry Settings

You can use the GetAllSettings to get a list of key settings and their values from a section in the Windows Registry. Here’s how you use GetAllSettings:

GetAllSettings( appname, section)

Here are the arguments for GetAllSettings:

  appname—String containing the name of the application whose key settings you want.
  section—String containing the name of the section whose key settings you want.

The GetAllSettings function returns a variant whose content is a two-dimensional array of strings, and these strings contain all the key settings in the indicated section and their values.

Deleting A Registry Setting

You can delete Registry settings with the DeleteSetting statement:

DeleteSetting  appname, section[, key]

Here are the arguments for DeleteSetting:

  appname—String expression containing the name of the application you want to work with.
  section—String expression containing the name of the section where the key you are deleting is stored. (If only appname and section are provided, the specified section is deleted along with all related key settings.)
  key—String expression containing the name of the key setting being deleted.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.