在网上看过例子,但是对中文支持不好。。。。(这个是自己写的,实现了对中文的支持)
以下两种方法,喜欢用哪个就用哪个
以下放在模块中
程序代码: | [ 复制代码 ] |
'***********************************************************
'**模 块 名 ModIniFile
'**作 用 INI文件操作(包括,读、写、删除),很方便,对中文支持很好。
'**作 者 石陆
'**制作日期 2007年12月8日9:57:31
'**修 改
'**修改日期
'**石陆软件屋 http://www.cnng.net
'***********************************************************
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'完成 d:\123.ini 内容如下-------写INI
'
'[main]
'Caption = 石陆软件屋
'例句 SaveINI "main", "Caption", "石陆软件屋", "D:\123.ini"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'd:\123.ini 内容如下-------读取INI
'
'[main]
'Caption = 石陆软件屋
'例句 GetINI("main", "Caption", "'http://www.cnng.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
'**模 块 名 ModIniFile
'**作 用 INI文件操作(包括,读、写、删除),很方便,对中文支持很好。
'**作 者 石陆
'**制作日期 2007年12月8日9:57:31
'**修 改
'**修改日期
'**石陆软件屋 http://www.cnng.net
'***********************************************************
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'完成 d:\123.ini 内容如下-------写INI
'
'[main]
'Caption = 石陆软件屋
'例句 SaveINI "main", "Caption", "石陆软件屋", "D:\123.ini"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'd:\123.ini 内容如下-------读取INI
'
'[main]
'Caption = 石陆软件屋
'例句 GetINI("main", "Caption", "'http://www.cnng.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.cls
程序代码: | [ 复制代码 ] |
'***********************************************************
'**类模块名 classIniFile
'**作 用 INI文件操作(包括,读、写、删除),很方便,对中文支持很好。
'**作 者 石陆
'**制作日期 2007年12月8日9:47:44
'**修 改
'**修改日期
'**石陆软件屋 http://www.cnng.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://www.cnng.net
'***********************************************************
Public Property Let INIFileName(ByVal New_IniPath As String)
strINI = New_IniPath
End Property
'***********************************************************
'**属性过程 INIFileName
'**作 用 返回INI文件名字
'**作 者 石陆
'**制作日期 2007年12月8日9:53:06
'**修 改
'**修改日期
'**石陆软件屋 http://www.cnng.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
'**类模块名 classIniFile
'**作 用 INI文件操作(包括,读、写、删除),很方便,对中文支持很好。
'**作 者 石陆
'**制作日期 2007年12月8日9:47:44
'**修 改
'**修改日期
'**石陆软件屋 http://www.cnng.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://www.cnng.net
'***********************************************************
Public Property Let INIFileName(ByVal New_IniPath As String)
strINI = New_IniPath
End Property
'***********************************************************
'**属性过程 INIFileName
'**作 用 返回INI文件名字
'**作 者 石陆
'**制作日期 2007年12月8日9:53:06
'**修 改
'**修改日期
'**石陆软件屋 http://www.cnng.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
相关链接:vb | 在INI文件 | 操作 | 删除
[本日志由 admin 于 2013-11-01 10:54 PM 编辑]
引用通告地址 (0):
http://www.cnng.net/blog/trackback.asp?tbID=45
http://www.cnng.net/blog/trackback.asp?tbID=45&CP=GBK
http://www.cnng.net/blog/trackback.asp?tbID=45
http://www.cnng.net/blog/trackback.asp?tbID=45&CP=GBK