lisong770818(懒人)的API声明放在模块顶部,再给你两个函数,直接调用就行:
'读取键值
Public Function GetINIString_Zhc(strINIFileName As String, strSection As String, strKey As String) As String
On Error GoTo ErrorHandle
Dim strTmp As String
strTmp = Space(3000)
If Trim$(strINIFileName) <> "" And Dir$(Trim$(strINIFileName)) <> "" And _
Trim$(strSection) <> "" And Trim$(strKey) <> "" Then
Dim tmp As Integer
If GetPrivateProfileString(strSection, strKey, "", strTmp, 3000, strINIFileName) > 0 Then
GetINIString_Zhc = TrimAPIString$(strTmp)
Else
GetINIString_Zhc = ""
End If
Else
GetINIString_Zhc = ""
End If
Exit Function
ErrorHandle:
GetINIString_Zhc = ""
MsgBox ERR.Description + " GetINIString_Zhc", vbCritical
End Function
'写键值
Public Function SetINIString_Zhc(strINIFileName As String, strSection As String, strKey As String, strSetString As String) As Boolean
On Error GoTo ErrorHandle
Dim iWriteLen As Integer
If Trim$(strINIFileName) <> "" And _
Trim$(strSection) <> "" And Trim$(strKey) <> "" Then
iWriteLen = WritePrivateProfileString(strSection, strKey, Trim$(strSetString), strINIFileName)
If iWriteLen <> 0 Then
SetINIString_Zhc = True
Else
SetINIString_Zhc = False
End If
Else
SetINIString_Zhc = False
End If
Exit Function
ErrorHandle:
SetINIString_Zhc = False
MsgBox ERR.Description + " SetINIString_Zhc", vbCritical
Exit Function