我看好多人用读ini文件,是不是ini文件速度快啊?
能简单介绍下怎么用ini吗?
谢谢大家了
15 个解决方案
#1
这个百度一下一大把啊。。。
#2
看看这个:链接
http://baike.baidu.com/view/509647.htm#sub509647
读写ini有函数的,其实都可以普通文本模式读取,不过是读写ini函数的话可免去在全文检索节、参数之类的
读写ini有函数的,其实都可以普通文本模式读取,不过是读写ini函数的话可免去在全文检索节、参数之类的
#4
赞同2楼的
#5
没区别,INI就是文本文件!
#6
没区别...
ini有自己的格式而已,然后微软有API可以很方便的读取..
ini有自己的格式而已,然后微软有API可以很方便的读取..
#7
区别是不大的。用顺序读取文本文件的方法也能读参数啊。
但是读INI文件,主要是可以直接用关键字检索出来。
比方说INI文件里有个参数
你只需要一个语句就能读出来。
SqlDbUser = SGetINI(sINIFile, "系统配置", "DbUser", "?")
而不必去管它位于第几行第几个字符串。
Public Function SGetINI(sINIFile As String, sSection As String, sKey As String, sDefault As String) As String '读INI
Dim sTemp As String * 256
Dim nLength As Integer
sTemp = Space$(256)
nLength = GetPrivateProfileString(sSection, sKey, sDefault, sTemp, 255, sINIFile)
SGetINI = Left$(Trim(sTemp), Len(Trim(sTemp)) - 1)
End Function
但是读INI文件,主要是可以直接用关键字检索出来。
比方说INI文件里有个参数
你只需要一个语句就能读出来。
SqlDbUser = SGetINI(sINIFile, "系统配置", "DbUser", "?")
而不必去管它位于第几行第几个字符串。
Public Function SGetINI(sINIFile As String, sSection As String, sKey As String, sDefault As String) As String '读INI
Dim sTemp As String * 256
Dim nLength As Integer
sTemp = Space$(256)
nLength = GetPrivateProfileString(sSection, sKey, sDefault, sTemp, 255, sINIFile)
SGetINI = Left$(Trim(sTemp), Len(Trim(sTemp)) - 1)
End Function
#8
ini配置看起来有条理
自己可以配置属性,而不用关心第几行第几列
例子楼上的都给了
我来蹭点分
自己可以配置属性,而不用关心第几行第几列
例子楼上的都给了
我来蹭点分
#9
无非是为了方便.
#10
不过也是文本文件而已
论坛签名======================================================================
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html
如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖
如何给自己的回帖中也加上签名?
http://blog.csdn.net/q107770540/archive/2011/03/15/6250007.aspx
论坛签名======================================================================
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html
如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖
如何给自己的回帖中也加上签名?
http://blog.csdn.net/q107770540/archive/2011/03/15/6250007.aspx
#11
个人也觉得用微软的api好用,配置起来方便。
但是不同要求用不同的方法吧
API的
txt的
但是不同要求用不同的方法吧
API的
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 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 WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Function ReadIniFile(ByVal strSection As String, ByVal strKey As String, _
Optional ByVal blnStoreDefaultValue As Boolean = False, _
Optional ByVal strKeyValue As String = "") As String
Dim strReadBuffer As String * 1024
Dim lngReturn As Long
lngReturn = GetPrivateProfileString(strSection, strKey, "", strReadBuffer, Len(strReadBuffer), gStation.IniFile)
If lngReturn = 0 And blnStoreDefaultValue = True Then
WriteIniFile strSection, strKey, strKeyValue
lngReturn = GetPrivateProfileString(strSection, strKey, "", strReadBuffer, Len(strReadBuffer), gStation.IniFile)
End If
ReadIniFile = Left(strReadBuffer, lngReturn)
End Function
Public Function WriteIniFile(ByVal strSection As String, ByVal strKey As String, _
ByVal strKeyValue As String) As Long
'Dim strReadBuffer As String * 1024
'Dim lngReturn As Long
'WriteIniFile = True
'lngReturn = GetPrivateProfileSection(strSection, strReadBuffer, Len(strReadBuffer), gStation.IniFile)
'If lngReturn = 0 Then
' WriteIniFile = WritePrivateProfileSection(strSection, "", gStation.IniFile)
' If WriteIniFile = False Then Exit Function
'End If
WriteIniFile = WritePrivateProfileString(strSection, strKey, strKeyValue, gStation.IniFile)
End Function
txt的
Txtfiles = CommonDialog1.FileName
Open Txtfiles For Input As #1
While Not EOF(1)
Line Input #1, b(count)
count = count + 1
Wend
Close #1
#12
特定格式的文本文件 有专门的API读写不需要你去分析文本 普通文本需自己分析才能获取需要的内容
#13
'读取INI
Public 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
Public 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
Public 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 Function ReadString(Section As String, key As String, Size As Long, iniFileName As String) As String
Dim ReturnStr As String
Dim ReturnLng As Long
ReadString = vbNullString
ReturnStr = Space(Size)
ReturnLng = GetPrivateProfileString(Section, key, vbNullString, ReturnStr, Size, iniFileName)
ReadString = Left(ReturnStr, ReturnLng)
End Function
Public Function ReadInt(Section As String, key As String, iniFileName As String) As Long
Dim ReturnLng As Long
ReadInt = 0
ReturnLng = GetPrivateProfileInt(Section, key, 0, iniFileName)
If ReturnLng = 0 Then
ReturnLng = GetPrivateProfileInt(Section, key, 1, iniFileName)
If ReturnLng = 1 Then
ErrorMsg = "INI文件不能正确读取"
Exit Function
End If
End If
ReadInt = ReturnLng
End Function
'读取文本文件
dim FileName as string
FileName="C:\TEST.TXT"
Public Function Readtxt(FileName As String) As String
Dim strTmp As String
Dim x As Integer
Open FileName For Input As #1
If LOF(1) > 0 Then
Readtxt = ""
While Not EOF(1)
x = DoEvents
Line Input #1, strTmp
'每读一行,调用处理
Readtxt = Readtxt + ChuLiStr(strTmp)
Wend
End If
Close #1
End Function
#14
估计ini文件接近Random文件,速度应该比顺序文件快
#15
大家都说完了,本质是一样的,操作手段不同而已。楼主可以自己做个专用格式,还可以封装一批专用api函数来访问,要是能实现的话楼主就彻底大悟了。
#1
这个百度一下一大把啊。。。
#2
看看这个:链接
http://baike.baidu.com/view/509647.htm#sub509647
读写ini有函数的,其实都可以普通文本模式读取,不过是读写ini函数的话可免去在全文检索节、参数之类的
读写ini有函数的,其实都可以普通文本模式读取,不过是读写ini函数的话可免去在全文检索节、参数之类的
#3
#4
赞同2楼的
#5
没区别,INI就是文本文件!
#6
没区别...
ini有自己的格式而已,然后微软有API可以很方便的读取..
ini有自己的格式而已,然后微软有API可以很方便的读取..
#7
区别是不大的。用顺序读取文本文件的方法也能读参数啊。
但是读INI文件,主要是可以直接用关键字检索出来。
比方说INI文件里有个参数
你只需要一个语句就能读出来。
SqlDbUser = SGetINI(sINIFile, "系统配置", "DbUser", "?")
而不必去管它位于第几行第几个字符串。
Public Function SGetINI(sINIFile As String, sSection As String, sKey As String, sDefault As String) As String '读INI
Dim sTemp As String * 256
Dim nLength As Integer
sTemp = Space$(256)
nLength = GetPrivateProfileString(sSection, sKey, sDefault, sTemp, 255, sINIFile)
SGetINI = Left$(Trim(sTemp), Len(Trim(sTemp)) - 1)
End Function
但是读INI文件,主要是可以直接用关键字检索出来。
比方说INI文件里有个参数
你只需要一个语句就能读出来。
SqlDbUser = SGetINI(sINIFile, "系统配置", "DbUser", "?")
而不必去管它位于第几行第几个字符串。
Public Function SGetINI(sINIFile As String, sSection As String, sKey As String, sDefault As String) As String '读INI
Dim sTemp As String * 256
Dim nLength As Integer
sTemp = Space$(256)
nLength = GetPrivateProfileString(sSection, sKey, sDefault, sTemp, 255, sINIFile)
SGetINI = Left$(Trim(sTemp), Len(Trim(sTemp)) - 1)
End Function
#8
ini配置看起来有条理
自己可以配置属性,而不用关心第几行第几列
例子楼上的都给了
我来蹭点分
自己可以配置属性,而不用关心第几行第几列
例子楼上的都给了
我来蹭点分
#9
无非是为了方便.
#10
不过也是文本文件而已
论坛签名======================================================================
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html
如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖
如何给自己的回帖中也加上签名?
http://blog.csdn.net/q107770540/archive/2011/03/15/6250007.aspx
论坛签名======================================================================
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html
如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖
如何给自己的回帖中也加上签名?
http://blog.csdn.net/q107770540/archive/2011/03/15/6250007.aspx
#11
个人也觉得用微软的api好用,配置起来方便。
但是不同要求用不同的方法吧
API的
txt的
但是不同要求用不同的方法吧
API的
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 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 WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Function ReadIniFile(ByVal strSection As String, ByVal strKey As String, _
Optional ByVal blnStoreDefaultValue As Boolean = False, _
Optional ByVal strKeyValue As String = "") As String
Dim strReadBuffer As String * 1024
Dim lngReturn As Long
lngReturn = GetPrivateProfileString(strSection, strKey, "", strReadBuffer, Len(strReadBuffer), gStation.IniFile)
If lngReturn = 0 And blnStoreDefaultValue = True Then
WriteIniFile strSection, strKey, strKeyValue
lngReturn = GetPrivateProfileString(strSection, strKey, "", strReadBuffer, Len(strReadBuffer), gStation.IniFile)
End If
ReadIniFile = Left(strReadBuffer, lngReturn)
End Function
Public Function WriteIniFile(ByVal strSection As String, ByVal strKey As String, _
ByVal strKeyValue As String) As Long
'Dim strReadBuffer As String * 1024
'Dim lngReturn As Long
'WriteIniFile = True
'lngReturn = GetPrivateProfileSection(strSection, strReadBuffer, Len(strReadBuffer), gStation.IniFile)
'If lngReturn = 0 Then
' WriteIniFile = WritePrivateProfileSection(strSection, "", gStation.IniFile)
' If WriteIniFile = False Then Exit Function
'End If
WriteIniFile = WritePrivateProfileString(strSection, strKey, strKeyValue, gStation.IniFile)
End Function
txt的
Txtfiles = CommonDialog1.FileName
Open Txtfiles For Input As #1
While Not EOF(1)
Line Input #1, b(count)
count = count + 1
Wend
Close #1
#12
特定格式的文本文件 有专门的API读写不需要你去分析文本 普通文本需自己分析才能获取需要的内容
#13
'读取INI
Public 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
Public 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
Public 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 Function ReadString(Section As String, key As String, Size As Long, iniFileName As String) As String
Dim ReturnStr As String
Dim ReturnLng As Long
ReadString = vbNullString
ReturnStr = Space(Size)
ReturnLng = GetPrivateProfileString(Section, key, vbNullString, ReturnStr, Size, iniFileName)
ReadString = Left(ReturnStr, ReturnLng)
End Function
Public Function ReadInt(Section As String, key As String, iniFileName As String) As Long
Dim ReturnLng As Long
ReadInt = 0
ReturnLng = GetPrivateProfileInt(Section, key, 0, iniFileName)
If ReturnLng = 0 Then
ReturnLng = GetPrivateProfileInt(Section, key, 1, iniFileName)
If ReturnLng = 1 Then
ErrorMsg = "INI文件不能正确读取"
Exit Function
End If
End If
ReadInt = ReturnLng
End Function
'读取文本文件
dim FileName as string
FileName="C:\TEST.TXT"
Public Function Readtxt(FileName As String) As String
Dim strTmp As String
Dim x As Integer
Open FileName For Input As #1
If LOF(1) > 0 Then
Readtxt = ""
While Not EOF(1)
x = DoEvents
Line Input #1, strTmp
'每读一行,调用处理
Readtxt = Readtxt + ChuLiStr(strTmp)
Wend
End If
Close #1
End Function
#14
估计ini文件接近Random文件,速度应该比顺序文件快
#15
大家都说完了,本质是一样的,操作手段不同而已。楼主可以自己做个专用格式,还可以封装一批专用api函数来访问,要是能实现的话楼主就彻底大悟了。