A little experience in using the INI file in the VB application

xiaoxiao2021-03-06  37

First, INI file overview

Windows Ini files can be interpreted as a Windows initialization file. It is a text file specifically designed to save applications and run environment information. For example, two famous INI files in Windows 3.1 Win.ini and System.ini define settings in the Windows environment in the Windows environment, the shell, the shell (shell) program, and the like. Many applications included in the Windows system have their own INI files, such as the control panel's INI file for Control.ini, which also defines the settings of the control panel. The INI file is a text file that edits through a text editor such as NotePad. The INI file has a specific format. An INI file is composed of several sections, and each segment contains several keywords (key) and corresponding values ​​(Value). The format of the segment is as follows:

[Sectionname]

Keyname = Value

Where sectionName and Keyname are segment names and keyword names, Value is a set value corresponding to the keyword. It is necessary to pay attention to:

(1) Segment name must be "[" and "]", and "[" must be on the first column of the screen;

(2) Keyword names must also be written from the first column of the screen, and the back must be tight with "=";

(3) You can comment on the document, and each line of comments must begin with ";".

In Windows, you can change the application settings by manually editing the INI file. If you want to change the Windows shell to the file manager, you can change "shell = progman.exe" under the [boot] section of System.ini to "shell = Winfile.exe". Some settings can also be changed directly on the application interface, but actually saved these modifications by modifying the INI file.

Second, several Windows API functions of the INI file in VB

When developing an application, we can create an application's own INI file. Save some of the operating environment information of the application via the INI file, and then read the setting information in the INI file and processed. Once the runtime environment needs to be changed, you can ensure the availability of the program by directing the INI file or indirectly modifying the INI file indirectly in the program.

VB (Visual Basic) is a very popular object-oriented programming language in recent years, but VB itself does not provide functions of manipulating the INI file. Fortunately, VB supports calls for DLL (Dynamic Link Library). (A DLL is actually an external function set for other applications that support DLL calls.) The function in the DLL is called an API (Application Programming Interface, Application Programming Interface) function. We can implement the function of manipulating the INI file by calling the corresponding API function. The relevant API functions are listed below and their descriptions. Before using these functions, you must first declare them with a Declare statement in the VB module file (.bas).

转载请注明原文地址:https://www.9cbs.com/read-62927.html

New Post(0)