讀寫INI檔案的四個函式 (轉)
'名.ini檔案
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
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
'以下兩個,讀/寫ini檔案,固定節點setting,in_key為寫入/讀取的主鍵
'僅僅針對是非值
'Y:yes,N:no,E:error
Public Function GetIniTF(ByVal In_Key As String) As Boolean
On Error GoTo GetIniTFErr
GetIniTF = True
Dim GetStr As String
GetStr = 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
GoTo GetIniTFErr
End If
Exit Function
GetIniTFErr:
Err.Clear
GetIniTF = False
GetStr = ""
End Function
Public Function WriteIniTF(ByVal In_Key As String, ByVal In_Data As Boolean) As Boolean
On Error GoTo WriteIniTFErr
WriteIniTF = True
If In_Data = True Then
WritePrivateProfileString "Setting", In_Key, "1", App.Path & "SourceDB.ini"
Else
WritePrivateProfileString "Setting", In_Key, "0", App.Path & "SourceDB.ini"
End If
Exit Function
WriteIniTFErr:
Err.Clear
WriteIniTF = False
End Function
'以下兩個函式,讀/寫ini檔案,不固定節點,in_key為寫入/讀取的主鍵
'針對字串值
'空值表示出錯
Public Function GetIniStr(ByVal AppName As String, ByVal In_Key As String) As String
On Error GoTo GetIniStrErr
If VBA.Trim(In_Key) = "" Then
GoTo GetIniStrErr
End If
Dim GetStr As String
GetStr = VBA.String(128, 0)
GetPrivateProfileString AppName, In_Key, "", GetStr, 256, App.Path & "SourceDB.ini"
GetStr = VBA.Replace(GetStr, VBA.Chr(0), "")
If GetStr = "" Then
GoTo GetIniStrErr
Else
GetIniStr = GetStr
GetStr = ""
End If
Exit Function
GetIniStrErr:
Err.Clear
GetIniStr = ""
GetStr = ""
End Function
Public Function WriteIniStr(ByVal AppName As String, ByVal In_Key As String, ByVal In_Data As String) As Boolean
On Error GoTo WriteIniStrErr
WriteIniStr = True
If VBA.Trim(In_Data) = "" Or VBA.Trim(In_Key) = "" Or VBA.Trim(AppName) = "" Then
GoTo WriteIniStrErr
Else
WritePrivateProfileString AppName, In_Key, In_Data, App.Path & "SourceDB.ini"
End If
Exit Function
WriteIniStrErr:
Err.Clear
WriteIniStr = False
End Function
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-993703/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- VB讀寫ini檔案 (轉)
- API讀取寫入 ini檔案內容的方法函式詳解API函式
- java 讀寫 ini 配置檔案Java
- c#讀寫ini檔案C#
- VB.NET 讀寫ini檔案
- 使用C#讀寫ini檔案C#
- delphi讀取ini檔案 (轉)
- C#關於讀寫INI檔案C#
- C# winform中讀寫ini檔案C#ORM
- linux/windows 讀寫ini配置檔案LinuxWindows
- C#中讀寫INI配置檔案C#
- 使用IniEditor讀寫INI型別配置檔案型別
- PHP獲取和操作配置檔案php.ini的幾個函式PHP函式
- 瞧瞧這個將CBitmap寫到Bmp檔案裡的函式 (轉)函式
- C語言fgetc()函式:讀檔案函式(由檔案中讀取一個字元)C語言函式字元
- 在Visual C++中使用fopen()函式來讀寫檔案 (轉)C++函式
- winform c#寫ini檔案ORMC#
- 建立與讀取.ini檔案
- C語言lseek()函式:移動檔案的讀寫位置C語言函式
- C#讀取ini配置檔案C#
- Python常用配置檔案ini、json、yaml讀寫總結PythonJSONYAML
- C++ 的函式分檔案編寫C++函式
- VB原始碼推薦:一個操作Ini檔案的類 (轉)原始碼
- php函式入門學習(陣列常見函式2 & 檔案基礎讀寫)PHP函式陣列
- 檔案的讀寫
- ini檔案解析c庫(iniparser)【轉】
- 第五篇:使用無緩衝IO函式讀寫檔案函式
- PCX 圖象檔案格式的讀寫 (轉)
- 四個PHP應用小函式 (轉)PHP函式
- 一個四捨五入函式 (轉)函式
- 透過python讀取ini配置檔案Python
- C語言putc()函式:寫檔案函式(將一指定字元寫入檔案中)C語言函式字元
- 各類檔案管理函式 (轉)函式
- 教你如何運用python實現簡單檔案讀寫函式Python函式
- 輕輕鬆鬆找檔案--支援回撥函式的通用檔案查詢函式 (轉)函式
- 檔案讀寫
- 關於onethink 目錄,檔案讀寫檢測函式中的問題函式
- C語言fputc()函式:寫檔案函式(將一指定字元寫入檔案流中)C語言函式字元