Results 1 to 20 of 20

Thread: Working with Windows Registry using Visual Basic 6 - A complete Tutorial

Threaded View

  1. #4

    Thread Starter
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Reading from The Windows Registry

    Now that we have the MyApp's startup form's .Top value saved in the Windows Registry, we need to access the value whenever our program starts up. We'll use the Visual Basic GetSetting function to read this value from the Windows Registry, and a good place to execute that function is in the Load Event Procedure of the form. Before I show you that code, let me show you the format for the GetSetting function.

    Syntax

    GetSetting(appname, section, key[, default])

    The GetSetting function syntax has thesenamed arguments:

    Part Description
    appname Required String expression containing the name of the application or project whose key setting is requested.
    section Required String expression containing the name of the section where the key setting is found.
    key Required String expression containing the name of the key setting to return.
    default Optional Expression containing the value to return if no value is set in the key setting. If omitted, default is assumed to be a zero-length string ("").

    As you can see, the first three arguments of the GetSetting function are identical to the SaveSetting statement. The difference lies in the fourth argument. With the SaveSetting Statement, the fourth argument was the value to be written to the Registry. For the GetSetting function, the fourth argument is an optional argument used to specify a default value to be returned in the event that the entry specified cannot be located in the Windows Registry.

    Here's the code to place in the Load Event Procedure of the Startup Form. I have inserted 2 message box in the code below so that you can understand how it works...

    vb Code:
    1. Private Sub Form_Load()
    2.     '~~> Check what is the current top value
    3.     MsgBox Form1.Top
    4.     '~~> Get value from registry
    5.     Form1.Top = GetSetting("MyApp", "Startup", "Top", 25)
    6.     '~~> Check the new top value
    7.     MsgBox Form1.Top
    8. End Sub
    Last edited by Siddharth Rout; Mar 26th, 2009 at 03:51 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width