Simple way to store strings in the Registry

Level:
Level1

When I first started to learn how to program Windows applications I was mystified by the Windows Registry. I discovered that programs would store information there and most "normal" users would never even know about it. This was the perfect place to store encrypted passwords and things like that. Of course now days the registry is becoming less and less helpful because it has grown enormously and is a pain to move when a computer is upgraded. Still storing a value in the registry, especially program settings or things such as that, can be very helpful. This code snippet shows you how to use Visual Basic's built in SaveSetting and GetSetting commands to store and retrieve data in the registry.

To use this code create a new Visual Basic project, add two command buttons to it, add two text boxes. Go to the code area and add the following source code.

  1. Private Sub Command1_Click()
  2.         SaveSetting "MyString", "New", "Test", Text1.Text
  3. End Sub
  4.  
  5. Private Sub Command2_Click()
  6.         Text2.Text = GetSetting("MyString", "New", _
  7.                 "Test", vbNullString)
  8. End Sub
  9.  
  10. Private Sub Form_Load()
  11.         Text1.Text = "This is a Test"
  12.         Command1.Caption = "Write Value"
  13.         Command2.Caption = "Read Value"
  14. End Sub

After you have added the source, run your program and you should be able to save and retrieve data from the registry.

Note: The source for this was found at DreamVB which is no longer online.

Private Sub

Private Sub cmdsave_Click()

Set rs = New ADODB.Recordset
rs.Open "select * from table1", cn, adOpenKeyset, adLockOptimistic
rs.AddNew
rs!id = txtid.Text
rs!Name = txtname.Text
rs!age = txtage.Text
rs!address = txtaddress.Text
rs!profile = txtprofile.Text
rs.Update
MsgBox "Saved!"
Form1.clear
rs.Close
Set rs = Nothing

End Sub

help

how to save text in vb6
i use adodc1.recordset.save and
it just clear the text in the text area

How to create a colored

How to create a colored message box in vb6.0

Useful in everyday programming!

This is what I'm looking for my system to work without any database to store my system settings.. Thank you for this very useful information.. ^_^

Mayo akong maginibo

Mayo akong maginibo

Database

please i need to connect the access 2003 to vb6 i need some help.

Thanks

Is your concern already

Is your concern already answered?
if not...

SAMPLE:

Private Sub cmdsave_Click()

Set rs = New ADODB.Recordset
rs.Open "select * from table1", cn, adOpenKeyset, adLockOptimistic
rs.AddNew
rs!id = txtid.Text
rs!Name = txtname.Text
rs!age = txtage.Text
rs!address = txtaddress.Text
rs!profile = txtprofile.Text
rs.Update
MsgBox "Saved!"
Form1.clear
rs.Close
Set rs = Nothing

End Sub

Cool!

Now I can Copy and Paste, AND store and retrieve data from the registry at the same time!!!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options