How does VB use INI files?

Source: Internet
Author: User

To make it easier for users to use and make the system flexible, most Win-dows applications record user choices and various changes in the system information in the initialization (INI) file. Therefore, when the system environment changes, you can directly modify the INI file without modifying the program. It can be seen that the INI file is crucial to system functions. This article describes how to read and write INI files when using Visual basicforwindows (VB) to develop Windows applications.
An INI file is a text file consisting of several sections. under each heading with parentheses, It is a number of keywords that begin with a single word (keyword) and an equal sign, each keyword controls how a function of an application works. The value on the right of the equal sign specifies the keyword operation method. The general form is as follows:
[Section1]
KeyWord1 = Valuel
KeyWord2 = Value2
......
[Section2]
KeyWord1 = Value1
KeyWord2 = Value2
......
If there is no content on the right of the equal sign (that is, the Value is null), it means that the Windows application has specified the default Value for this keyword, if a keyword (or entire part) cannot be found in the entire file, it also indicates that the default value is specified for them. The order in which each part appears is irrelevant. In each part, the order of each keyword is also irrelevant.
There are two ways to read and write INI files: one is to use Notepad in Windows to edit it, which is relatively simple and does not need to be described in detail; the other is to read and write INI files by Windows applications, normally, the application reads information in the INI file when running the program, and saves some modifications to the running environment when exiting the application.
The Value Type of a keyword is string or integer. You can read and write the keyword in two cases. In order to make the program maintainability and portability, it is best to encapsulate the INI file read and write in a module (RWINI. in BAS), construct the GetIniS and GetIniN functions in the RWI-NI.BAS and the SetIniS and Se-tIniN processes, in these functions and procedures, you must use the "GetPrivateprofileString", "GetPrivateProfileInt", and "WritePrivateProfileString" functions of WindowsAPI.
The program code of the RWINI. BAS module is as follows:
Declare the WindowsAPI function used in the General-Declearation section:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.