'***********************************************************
'**模 块 名 ModIniFile
'**作 用 INI文件操作(包括,读、写、删除),很方便,对中文支持很好。
'**作 者 石陆
'**制作日期 2007年12月8日9:57:31
'**修 改
'**修改日期
'**石陆软件屋
http://baidu.bzzo.net'***********************************************************
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'完成 d:\123.ini 内容如下-------写INI
'
'[main]
'Caption = 石陆软件屋
'例句 SaveINI "main", "Caption", "石陆软件屋", "D:\123.ini"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'd:\123.ini 内容如下-------读取INI
'
'[main]
'Caption = 石陆软件屋
'例句 GetINI("main", "Caption", "'
http://baidu.bzzo.net", "D:\123.ini")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, 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 String, ByVal lpString As Any, ByVal lpFileName As String) As Long
'Const pa As String = "C:\Users\BAIDU-ZCY\Desktop\ccc.ini"
Public Function WriteINI(ByVal Genus As String, ByVal Item As String, ByVal Value As String, ByVal InIname As String) As Long
WriteINI = WritePrivateProfileString(Genus, Item, Value, InIname)
End Function
Public Function ReadINI(ByVal Genus As String, ByVal Item As String, ByVal Default As String, ByVal InIname As String) As String
ReadINI = String$(255, 0)
GetPrivateProfileString Genus, Item, Default, ReadINI, 256, InIname
ReadINI = Replace(ReadINI, Chr(0), "")
End Function
Sub DelItem(ByVal Genus As String, ByVal Item As String, ByVal InIname As String)
WritePrivateProfileString Genus, Item, 0&, InIname
End Sub
Sub DelItemAll(ByVal Genus As String, ByVal InIname As String)
WritePrivateProfileSection Genus, "", InIname
End Sub
Sub DelSec(ByVal Genus As String, ByVal InIname As String)
WritePrivateProfileSection Genus, 0&, InIname
End Sub
'***********************************************************
'**类模块名 classIniFile
'**作 用 INI文件操作(包括,读、写、删除),很方便,对中文支持很好。
'**作 者 石陆
'**制作日期 2007年12月8日9:47:44
'**修 改
'**修改日期
'**石陆软件屋
http://baidu.bzzo.net'***********************************************************
Option Explicit
Private strINI As String
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
Public Sub WriteIniKey(strSection As String, strKey As String, strValue As String)
WritePrivateProfileString strSection, strKey, strValue, strINI
End Sub
Public Function GetIniKey(strSection As String, strKey As String, ByVal Default As String) As String
GetIniKey = String$(255, 0)
GetPrivateProfileString strSection, strKey, Default, GetIniKey, 256, strINI
GetIniKey = Replace(GetIniKey, Chr(0), "")
End Function
'***********************************************************
'**属性过程 INIFileName
'**作 用 设置INI文件名字
'**作 者 石陆
'**制作日期 2007年12月8日9:51:59
'**修 改
'**修改日期
'**石陆软件屋
http://baidu.bzzo.net'***********************************************************
Public Property Let INIFileName(ByVal New_IniPath As String)
strINI = New_IniPath
End Property
'***********************************************************
'**属性过程 INIFileName
'**作 用 返回INI文件名字
'**作 者 石陆
'**制作日期 2007年12月8日9:53:06
'**修 改
'**修改日期
'**石陆软件屋
http://baidu.bzzo.net'***********************************************************
Public Property Get INIFileName() As String
INIFileName = strINI
End Property
Public Function DelIniKey(ByVal SectionName As String, ByVal KeyWord As String)
WritePrivateProfileString SectionName, KeyWord, 0&, strINI
End Function
Public Function DelIniSec(ByVal SectionName As String) '清除section
WritePrivateProfileString SectionName, 0&, "", strINI
End Function
评论