Introduction The final start is in Windows 3.x, which is used to save data for OLE. At that time, Windows and its application set values were saved in different .ini files. For example, we are the most familiar system.ini and win.ini are such a file. The more the software is more and more, and this file is getting more and more, and all the corners of the hard drive. It is not easy to manage, but also a lot of disk space (because most of these files are very small). When Windows 95 is launched, the registry encourages. All settings values, whether systemically or applications, are saved in a database of a tree structure. This is indeed a lot of convenience, and it provides better support for multi-user environments. For programmers, there must be some, you must understand the structure of the registry, but because the registry is no longer a single text file, you must use a dedicated function to operate the registry. Registry (registry) is the best place to save the program running parameters and user settings. After listening to too many warnings, the editorial registration table seems to be a mysterious and complicated thing to many people, but in VB, through four registry functions, everything becomes simple. If you have some understanding of the registry, you should know the structure of the registry and the structure of the file system we are familiar with, are the tree structure. Use the primary key instead of the directory to divide a variety of different information. There are also submersible and three different types of key values below the primary key. Each key value can be one of a string, a binary value, or a double word value. Visual Basic provides a standard registration location (primary key) to store program information created at Visual Basic: hkey_current_user / software / vb and vba program settings / All functions read and written are in this The path is the relative position of the root. SAVESETTING This function is used to write some data SAVESETING AppName, Section, Key, and Setting Appname before writing data to the registry, you must plan a Appname throughout the application before writing data to the registry. You can make a computer for the content of the registry, then appname is the drive. It must be a string or use numbers, but use the CSTR function to convert it into a string format. In fact it represents the name of the application or engineering. In general, AppName should remain inconvenient throughout the application. Section section can be said to be the directory in this model, just like a directory on a computer. It is used to set the set classifier, which can contain key or subsection. If it passes the value of VBNullChar, it means that the button to operate is in the root directory, that is, under Appname. Key is equivalent to a file name. Setting It represents information in the file, which can be a number or string. After executing, the key name "key" below the hkey_current_user / software / vb and vba program settings / appname / section / "Programs below will be assigned" setting ", if the corresponding primary key or the key name does not exist. It will be created. GetSetting This function is used to extract data from the registry. GetSetting (AppName, Section, Key [, Default]) AppName, Section, and Key The meaning of the above. Default If Visual Basic is not found Key, the function will return to the parameter default.
This parameter is optional, but it is very convenient to handle the error. If this parameter is not selected, the name of the specified key does not exist, the function will return a string of length 0. Let's take a look: Savesetting "Logon Master", "UserS / User0", _ "Name", "John" comment: This will store data "john" to "Logon Master / Users / User0 / Name" comment on the registry : However, this is a relative path, relative to a root Debug.Print getSetting ("Logon Master", _ "User0", "Name", "Anonymous" comment: This will display "John" debug.print getSetting ("Logon" Master ", _" User1 "," Name "," anonymous "comment: This display will be" anonymous "because of the comment:" Logon Master / Users / User1 / Name "is not pre-stored. GetallSettings The function is used to extract all the files (sub-keys) below. The meaning of the getallSettings (AppName, Section) parameter is the same. But this function is more complicated than other than other than the other. What he returned is a 2-dimensional string array contains all the sub-key names and a child key value of the hometown. Let's see the example below. You can figure it out: Note: Define a variant type variable Save GetAllSettings Returned Two Two Note: The Interger Type value is used to count Dim MySettings As Variant, intSettings AS Integer Note: First fill in some value Savesetting "Logon Master", "UserS / User0", _ "Name" , "John" Savesetting "Logon Master", "UserS / User0", _ "Priviledges", "Supervisor" comment: Extract pre-set data MySettings = getallSettings ("Logon Master", _ "users / user0") Note: Displaying for intSettings = lbound (MySettings, 1) _to Ubound (MySettings, 1) Note: MySettings (x, 0) is included with key names, comments: and MySettings (x, 1) are key value deb Ug.Print MySettings (IntSettings, 0), _MySettings (INTSETTINGS, 1) Next IntSettings Note: getAllSettings does not return to the directory name, just returns the key name and the corresponding key value. In addition to saving and extracting data, we have to delete registration items in the registry. This is to use the deletesetting function. DELETESETTING AppName [, Section [, Key]] This function is used to delete the primary key or key.