ini文件读写一问,代码如下
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
Public Sub WriteToIni(ByVal Key As String, ByVal Value As String, Optional ByVal Section As String = "IniDefSection")
On Error Resume Next
Dim buff As String * 128
buff = Value + Chr(0)
'WritePrivateProfileString Section, Key, buff, GetIniFileName
WritePrivateProfileString Section, Key, buff, App.Path & "\set.ini"
End Sub
Public Function ReadFromIni(ByVal Key As String, Optional ByVal Section As String = "IniDefSection") As String
On Error Resume Next
Dim i As Long
Dim buff As String * 128
'GetPrivateProfileString Section, Key, "", buff, 128, GetIniFileName
GetPrivateProfileString Section, Key, "", buff, 128, App.Path & "\set.ini"
i = InStr(buff, Chr(0))
ReadFromIni = Trim(Left(buff, i - 1))
End Function