October 23, 2018
Hot Topics:

VB TIP: Using the GetSetting and SaveSetting Commands

  • November 19, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »
Option Explicit

Public Const ThisApp = "My Company"
Public Const ThisKey = "My Prog Name"

Public Declare Function RegOpenKeyEx _
   Lib "advapi32.dll" _
 Alias "RegOpenKeyExA" (_
         ByVal hKey As Long, _
         ByVal lpSubKey As String, _
         ByVal ulOptions As Long, _
         ByVal samDesired As Long, _
         phkResult As Long) As Long

Public Declare Function RegQueryValueEx _
    Lib "advapi32.dll" _
 Alias "RegQueryValueExA" ( _
         ByVal hKey As Long, 
         ByVal lpValueName As String, _
         ByVal lpReserved As Long, _
         ByVal lpType As Long, _
         ByVal lpData As Any, _
         lpcbData As Long) As Long

Public Declare Function RegCloseKey _
   Lib "advapi32.dll" _
         ByVal hKey As Long) As Long

Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_CURRENT_USER = &H80000001
Public Const READ_CONTROL = &H20000
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_NOTIFY = &H10
Public Const SYNCHRONIZE = &H100000
Public Const ERROR_SUCCESS = 0&
Public Const ERROR_MORE_DATA = 234
Public Const REG_SZ = 1

Public Const KEY_READ = ((READ_CONTROL Or _
                          KEY_QUERY_VALUE Or _
                          KEY_ENUMERATE_SUB_KEYS Or _
                          KEY_NOTIFY) And _
                          (Not SYNCHRONIZE))

Public Const KEY_EXECUTE = ((KEY_READ) And _
                            (Not SYNCHRONIZE))

Global Name As String
Global Phone As String
Global PostCode As String
Private Sub cmdLoad_Click()

Dim Name, Phone, PostCode As String

Name = GetSetting(ThisApp, ThisKey, "Name", "")
Phone = GetSetting(ThisApp, ThisKey, "Phone", "")
PostCode = GetSetting(ThisApp, ThisKey, "PostCode", "")

txtName.Text = (Name)
txtPhone.Text = (Phone)
txtPostCode.Text = (PostCode)

End Sub

Private Sub cmdSave_Click()

Dim Name, Phone, PostCode As String

SaveSetting ThisApp, ThisKey, "Name", txtName.Text
SaveSetting ThisApp, ThisKey, "Phone", txtPhone.Text
SaveSetting ThisApp, ThisKey, "PostCode", txtPostCode.Text

End Sub

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date