How to use the VB development application how to use INI files

zhaozj2021-02-11  248

How to use the VB development application How to use the INI file For the convenience of users, most Win-DOWS applications are recorded in the initialization (INI) file in the initialization (INI) file to facilitate the user's flexibility. Therefore, when the environment of the system changes, INI files can be directly modified without modifying the program. It can be seen that the INI file is critical to system functions. This article will introduce how to read and write the INI file when developing a Windows application using VisualBasicForWindows (hereinafter referred to). The INI file is a text file, which consists of several sections. Here's a header of each with a bracket, is a keyword that starts with a single word (Keyword) and one equal sign, each keyword will control the application Features work mode, the value of the right side (Value) specifies the operation mode of the keyword. The general form is as follows: [section1] keyword1 = valuelkeyword2 = value2 ... [section2] keyword1 = value1keyword2 = value2 ... where there is no content (ie, the value is empty), then the Windows application has been The keyword specifies the default value, and if a keyword (or whole part) is found throughout the file, it also indicates that the default value is specified. The order in which each part appears is irrelevant. In each portion, the order of each keyword is also significant. Reading and writing Ini files There are usually two ways: First, edit it with "Notepad" in Windows, it is relatively simple, and it is not necessary to read and write the INI file by the Windows application, usually the application run. Read the information in the INI file, save some modifications to the running environment when you exit the application. The type of keyword is mostly a string or integer type, and should be read and written in two cases. In order to make the program have maintainability and portability, it is best to make read and write packages on the INI file in a module (RWINI.BAS), construct Getinis and Getinin functions in rwi-ni.bas, and setinis and se-Tinin Procedure, in these functions and processes, you need to use WindowsAPI's "getPrivateProfileString", "getPrivateProfileint" and "WritePrivateProfileString" functions.

RWINI.BAS program code means as follows: Statement to the General-Declearation section WindowsAPI function: DeclareFunctionGetprivateprofileStringLib "Kernel" (ByVallpAppNameAsString, ByVallpKeyNameAsString, ByVallpDefaultAsString, ByVallpRetrm-StringAsString, ByValcbReturnStringAsInteger, ByValFilenameAsString) AsIntegerDeclareFunctionGetPrivatePfileIntLib "Kernel" (ByVallpAppNameAsString, ByVallpKeyNameAsString, ByVallpDefaultAsInteger, ByValFilenameAsString) AsIntegerDeclareFuncitonWritePrivateprofileStringLib "Kernel" (ByVallpApplicationNameAsString, ByVallpKeyNameAsString, ByVallpStringAsString, ByVallplFileNameAsString) AsIntegerFunctionGetIniS (ByValSectionNameAsString, ByValKeyWordAsString, ByValDefStringAsString) AsStringDimResultStringAsString * 144, TempAsIntegerDimsAsString, iAsIntegerTemp% = GetPrivateProfileString (SectionName, KeyWord, "", ResultString, 144, AppProfileName ()) 'Retrieving the value of the keyword iftemp%> 0Then' The value of keyword is not empty S = "" "" "" "fori = 1to144IFASC (RESULTSTRING, I, 1)) = 0THENEXITFORSES = S & MID $ (Resultstring, I, 1 ) EndifNextelseTemp% = WritePrivateProfilesstring (SectionName, K eyWord, DefString, ppProfileName ()) 'default value INI file is written s = DefStringEndIfGetIniS = sEndFunctionFunctionGetIniN (ByValSectionNameAsString, ByValKeyWordAsString, ByValDefValueAsIneger) AsIntegerDimdAsLong, sAsStringd = DefValueGetIniN = GetPrivateProfileInt (SectionName, KeyWord, DefValue, ppProfileName ()) Ifd <> DefValuethens = "" & DD = WritePrivateProfileString (SectionName, Keyword, S,

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

New Post(0)