Private 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
Private 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
Dim rtnValueA As Variant
Function WriteToIni(ByVal strFileName As String, ByVal strSectionName _
As String, ByVal strKeyName As String, ByVal strValue As String)
'将值写到INI文件中去
rtnValueA = WritePrivateProfileString(strSectionName, strKeyName, strValue, strFileName)
End Function
Function ReadFromIni(ByVal strFileName As String, ByVal strSectionName _
As String, ByVal strKeyName As String, ByVal strDefault As String)
Dim strOut As String * 255
'从INI文件中读取值
rtnValueA = GetPrivateProfileString(strSectionName, strKeyName, strDefault, strOut, 255, strFileName)
ReadFromIni = Trim(Replace(strOut, Chr(0), ""))
End Function
'---------------------------------------------------------------------------------
以上的两个函数,你自己用吧!
很简单的调用。