用VB.net实现对.ini文件的读写操作的类Option Explicit On Module INI ' keyName :配置项名 ' iniPath :INI配置文件的路径 ' //声明从INI配置文件中获取类型为Int的配置项的值的系统函数 //声明从INI配置文件中获取类型为string的配置项的值的系统函数 //声明向INI配置文件中写入类型为string的配置项的值的系统函数 Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer //从INI配置文件中获取类型为Int的配置项的值 Public Function GetIntFromINI(ByVal sectionName As String, ByVal keyName As String, ByVal defaultValue As Integer, ByVal iniPath As String) As Integer GetIntFromINI = GetPrivateProfileInt(sectionName, keyName, defaultValue, iniPath) //从INI配置文件中获取类型为string的配置项的值 Dim rc As Integer buffer = Space(256) rc = GetPrivateProfileString(sectionName, keyName, defaultValue, buffer, buffer.Length, iniPath) GetStrFromINI = Left(buffer, InStr(buffer, vbNullChar) - 1) //向INI配置文件中写入类型为string的配置项的值 Public Function WriteStrINI(ByVal sectionName As String, ByVal keyName As String, ByVal setValue As String, ByVal iniPath As String) As Integer rc = WritePrivateProfileString(sectionName, keyName, setValue, iniPath) If rc Then End Module |
|
来自: zjsxShenwx > 《VB.Net》