读写INI文件,我自己用的函数。保存为 bas 模块文件
程序代码:
'读写INI文件函数
Option Explicit
'写
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
'读
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
'保存到INI文件
Public Function Wini(ByVal 段 As String, ByVal 键 As String, ByVal 值 As String, IniFile As String) As Boolean
Dim X As Long, buff As String * 1024, i As Long
buff = 值 & Chr(0)
X = WritePrivateProfileString(段, 键, buff, IniFile)
Wini = X
End Function
'从INI文件中读取
Public Function Rini(ByVal 段 As String, ByVal 键 As String, IniFile As String) As String
Dim X As Long, buff As String * 1024, i As Long
X = GetPrivateProfileString(段, 键, "", buff, 1024, IniFile)
i = InStr(1, buff, Chr(0))
Rini = Trim(Left(buff, i - 1))
End Function