This article describes how to access the system registry using the four functions provided by VB.
Create a project and place two labels on Form1. The Caption attributes are "name" and "company", and the txtName and txtCompany Text attributes are set to null; the three command buttons are cmdSave, find, and delete. The Caption is set to save, view, and delete respectively ".
Add the following code to the three command buttons:
Private Sub cmdSave_Click () 'Assigns the content in the two text boxes to Name and Company in the User area under MyApp respectively. SaveSetting "MyApp", "User", "Name", txtName SaveSetting "MyApp", "User", "Company", txtCompany MsgBox "your information has been saved! ″ End Sub Private Sub partition find_click () 'Find the setting values of Name and Company in the User area of MyApp and display MsgBox "Your name is:" & GetSetting ("MyApp", "User ″, "Name") & Chr (13) & Chr (10) & "your company is :″ & GetSetting ("MyApp", "User", "Company ″) End Sub Private Sub partition delete_click () 'Delete the User region under MyApp and all registry items under MyApp DeleteSetting "MyApp", "User ″ End Sub
|
Run the program, enter the name and company name in the window, press "save", and then press "Search". The correct result is displayed, it indicates that the SAVE and search operations are normal. If you press the "Search" button before saving or after deletion, a dialog box is displayed, indicating that the registry key you are looking for does not exist.