VB讀寫ini檔案 (轉)
自從登錄檔誕生以來ini正在逐漸失去其市場佔有率,然而基於ini檔案的獨立性,致使其還沒有到達退出歷史舞臺的地步,很多應用的初始化和一些介面引數的設定仍然很願意從ini檔案中讀取,為了保證操作需用引數對ini檔案的讀取的通明性,建議使用一個模組來完成此工作。注:所有操作標準的Win 來完成。:namespace prefix = o ns = "urn:schemas--com::office" />
Dim Ret As Long
Dim Start As Long
Public FileName As String
Const BufSize = 10240
Dim buf As String * BufSize
Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, 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
Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, 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
Public Sub SetValue(ByVal clsName As String, ByVal key As String, ByVal V As String)
Ret = WritePrivateProfileString(clsName, key, V, FileName)
End Sub
Public Function GetValue(ByVal clsName As String, ByVal key As String) As String
Ret = GetPrivateProfileString(clsName, key, "", buf, BufSize, FileName)
Start = 1
GetValue = RetStr()
End Function
Private Function RetStr() As String
Dim i As Long
i = InStr(Start, buf, Chr(0))
If i > Start Then
RetStr = Mid(buf, Start, i - Start)
End If
Start = i + 1
End Function
至此已經完成了對一個完整的獨立模組的封裝,接下來就來看看怎麼引用(其實看完上面程式就明瞭了),
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-989645/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- VB.NET 讀寫ini檔案
- java 讀寫 ini 配置檔案Java
- c#讀寫ini檔案C#
- 讀寫INI檔案的四個函式 (轉)函式
- 使用C#讀寫ini檔案C#
- delphi讀取ini檔案 (轉)
- C#關於讀寫INI檔案C#
- C# winform中讀寫ini檔案C#ORM
- linux/windows 讀寫ini配置檔案LinuxWindows
- C#中讀寫INI配置檔案C#
- 使用IniEditor讀寫INI型別配置檔案型別
- VB原始碼推薦:一個操作Ini檔案的類 (轉)原始碼
- winform c#寫ini檔案ORMC#
- 建立與讀取.ini檔案
- go 讀取.ini配置檔案Go
- 在VB應用程式中使用INI檔案的一點體會 (轉)
- C#讀取ini配置檔案C#
- Python常用配置檔案ini、json、yaml讀寫總結PythonJSONYAML
- ini檔案解析c庫(iniparser)【轉】
- API讀取寫入 ini檔案內容的方法函式詳解API函式
- 透過python讀取ini配置檔案Python
- Vb下呼叫Help檔案 (轉)
- 檔案讀寫
- VB讀取文字檔案的例子:逐行讀取
- Linux下用C讀取INI配置檔案Linux
- 在VB中使用檔案物件 (轉)物件
- 檔案排版(文字檔案讀寫)
- 如何在PL/SQL中讀寫檔案(轉)SQL
- PCX 圖象檔案格式的讀寫 (轉)
- 直接透過DAO讀、寫Access檔案 (轉)
- java操作ini檔案Java
- Golang 讀、寫檔案Golang
- keras讀寫檔案Keras
- perl 讀寫檔案
- 檔案讀寫IO
- 檔案的讀寫
- Python讀取修改ini配置檔案[ConfigParser]Python
- Json檔案轉換為Excel檔案!涉及讀檔案,時間戳轉化,寫文件JSONExcel時間戳