Read and write four functions of the INI file

zhaozj2021-02-11  190

'Filename SourceDB.ini file 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 LongPrivate 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

'The following two functions, read / write INI files, fixed nods setting, IN_KEY is only non-value' Y: Yes, N: N: N: N: N: N: N: N: N: N: N: N: N: N: N:, E: ErrorPublic function getinitf (byvalin_key as string) As BooleanOn Error GoTo GetIniTFErrGetIniTF = TrueDim getStr As StringGetStr = VBA.String (128, 0) GetPrivateProfileString "Setting", In_Key, "", getStr, 256, App.Path & "/SourceDB.ini"GetStr = VBA.Replace (getStr , Vba.chr (0), "") if getStr = "1" Then getinitf = true getstr = "" "Else gotinitferrend ifxit functiongetinitferr: err.clear getinitf = false getstr =" "End Function

Public Function WriteIniTF (ByVal In_Key As String, ByVal In_Data As Boolean) As BooleanOn Error GoTo WriteIniTFErrWriteIniTF = TrueIf In_Data = True Then WritePrivateProfileString "Setting", In_Key, "1", App.Path & "/SourceDB.ini"Else WritePrivateProfileString" Setting ", In_key," 0 ", app.path &" /sourcedb.ini"end ifexit functionwriteinitferr: err.clear writeinitf = falsend function

'The following two functions, read / write INI files, unfixed nodes, IN_KEY to write / read primary key' for string value 'null values ​​indicate erry PUBLIC FUNITENISTR (Byval Appname As String, Byval In_Key AS String) AS StringOn Error GoTo GetIniStrErrIf VBA.Trim (In_Key) = "" Then GoTo GetIniStrErrEnd IfDim getStr As StringGetStr = VBA.String (128, 0) GetPrivateProfileString AppName, In_Key, "", getStr, 256, App.Path & "/SourceDB.ini "GetStr = VBA.Replace (GetStr, VBA.chr (0),") if getStr = "" "" GetStr Getstr = "" endstr = "" "GetStr genuctioninistrer: err.clear getinistr =" getStr = "" FunctionPublic Function WriteIniStr (ByVal AppName As String, ByVal In_Key As String, ByVal In_Data As String) As BooleanOn Error GoTo WriteIniStrErrWriteIniStr = TrueIf VBA.Trim (In_Data) = "" Or VBA.Trim (In_Key) = "" Or VBA.Trim ( Appname) = "" "" "" "" "IN_KEY, IN_DATA, App.Path &" /sourcedb.ini"end iFexit FunctionWriteinistrer: Err.clear Writeinistr = FalseEnd Function

转载请注明原文地址:https://www.9cbs.com/read-4850.html

New Post(0)