关于读写INI文件的问题!

csersoft 2011-12-21 12:15:59
这个代码在读写ini文件时有字数限制.
怎么把它改成无限制的???
先上一段读写INI文件的代码.

'声明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 WritePrivateProfileString Lib _
"kernel32" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal lpKeyName _
As Any, ByVal lpString As Any, ByVal lpFileName _
As String) As Long
'-------------------------------------------------
'声明变量
Private iniFile As String
Private iniSec As String
Private iniKey As String

'-------------------------------------
Public Property Let FileName(strfile As String)
If Right(strfile, 4) <> ".ini" Then
strfile = strfile & ".ini"
End If
iniFile = strfile
End Property

Public Property Get FileName() As String
FileName = iniFile
End Property

Public Property Let Section(strSection As String)
iniSec = strSection
End Property
Public Property Get Section() As String
Section = iniSec
End Property

Public Property Let Key(strKey As String)
iniKey = strKey
End Property
Public Property Get Key() As String
Key = iniKey
End Property
'读取INI文件中的条目
Public Function ReadItem(Optional ByVal strSection As String, Optional ByVal strKey As String)
Dim sTemp As String * 256
Dim nLen As Integer
sTemp = Space$(256)
'如果没有指定参数则按属性设置进行
If Len(strSection) > 0 Then
iniSec = strSection
End If
If Len(strKey) > 0 Then
iniKey = strKey
End If
nLen = GetPrivateProfileString(iniSec, iniKey, vbNullString, sTemp, 255, iniFile)
ReadItem = Left$(sTemp, nLen)
End Function
'将指定信息写入INI文件
Public Function WriteItem(ByVal value As String, Optional ByVal strSection As String, Optional ByVal strKey As String)

Dim x As Long, Buff As String * 256, i As Integer

'INI文件中的字符串必须以字符CHr(0)结尾
Buff = value + Chr(0)
If Len(strSection) > 0 Then
iniSec = strSection
End If
If Len(strKey) > 0 Then
iniKey = strKey
End If
x = WritePrivateProfileString(iniSec, iniKey, Buff, iniFile)
If x = 0 Then MsgBox "ini文件写入错误!", , ""

End Function

这个代码在读写ini文件时有字数限制.
怎么把它改成无限制的???
...全文
126 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinaboyzyq 2011-12-21
  • 打赏
  • 举报
回复
Dim sTemp As String * 512
Dim nLen As Integer
sTemp = Space$(512)

.
.
nLen = GetPrivateProfileString(iniSec, iniKey, vbNullString, sTemp, 512, iniFile)

---
Dim x As Long, Buff As String * 512, i As Integer

无·法 2011-12-21
  • 打赏
  • 举报
回复
2.如何用正则显示ini文件所有主键?数据例如:

[Windows 帮助]
H_WindowPosition=[426,266,426,266,0]
[SysParam]
RemPass=1
ServerCount=2
server0=127.0.0.1
UserCount=1



答:^/s*(/[.*/])/s*$



3.如何读取指定主键的键值?数据还是上面的,例如读取SysParam下面的server0



答:^/s/[SysParam/](?:.|/r|/n)*server0=(.*)/s$ 子匹配的第一项就是


参考:
http://blog.csdn.net/sysdzw/article/details/4646568
无·法 2011-12-21
  • 打赏
  • 举报
回复
[Quote=引用楼主 hack_bxc 的回复:]
这个代码在读写ini文件时有字数限制.
怎么把它改成无限制的???
先上一段读写INI文件的代码.
VB code

'声明API函数
Private Declare Function GetPrivateProfileString Lib _
"kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicatio……
[/Quote]自己去读取文件 纯字符分析吧
csersoft 2011-12-21
  • 打赏
  • 举报
回复
这样是不是只能读写512个字符?

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧