'声明 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 Set_ini(ByVal Field As String, ByVal Code As String, ByVal vNewValue As String) WritePrivateProfileString Field, Code, vNewValue, App.Path & "\config.ini" End Sub '==================读取============== Public Function Get_ini(ByVal Field As String, ByVal Code As String) As String Dim strTemp As String * 255 Dim n As Long n = GetPrivateProfileString(Field, Code, "", strTemp, Len(strTemp), App.Path & "\config.ini") Get_ini = Left(strTemp, n) End Function
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 Set_ini(ByVal Field As String, ByVal Code As String, ByVal vNewValue As String)
WritePrivateProfileString Field, Code, vNewValue, App.Path & "\config.ini"
End Sub
'==================读取==============
Public Function Get_ini(ByVal Field As String, ByVal Code As String) As String
Dim strTemp As String * 255
Dim n As Long
n = GetPrivateProfileString(Field, Code, "", strTemp, Len(strTemp), App.Path & "\config.ini")
Get_ini = Left(strTemp, n)
End Function
同意楼上