请问如何改写INI文件

lingjiadong 2003-08-20 05:22:01
我有个INI文件如下:
[Config]
inter=

[pp]
abc=
def=

请问我如果想把abc= def= 改为:bbb= ddd=
该怎么写这段程序,我现在主要的难点在如何找到[pp]这个字段,
而且如何在改了abc= 为 bbb= 后怎么定位到下一行
...全文
34 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dhyuser10 2003-08-20
  • 打赏
  • 举报
回复
gz
还想懒够 2003-08-20
  • 打赏
  • 举报
回复
用改文本文件的Open方法不行么?
Alicky 2003-08-20
  • 打赏
  • 举报
回复

lisong770818(懒人)的API声明放在模块顶部,再给你两个函数,直接调用就行:
'读取键值
Public Function GetINIString_Zhc(strINIFileName As String, strSection As String, strKey As String) As String
On Error GoTo ErrorHandle
Dim strTmp As String

strTmp = Space(3000)
If Trim$(strINIFileName) <> "" And Dir$(Trim$(strINIFileName)) <> "" And _
Trim$(strSection) <> "" And Trim$(strKey) <> "" Then
Dim tmp As Integer
If GetPrivateProfileString(strSection, strKey, "", strTmp, 3000, strINIFileName) > 0 Then
GetINIString_Zhc = TrimAPIString$(strTmp)
Else
GetINIString_Zhc = ""
End If
Else
GetINIString_Zhc = ""
End If

Exit Function
ErrorHandle:
GetINIString_Zhc = ""
MsgBox ERR.Description + " GetINIString_Zhc", vbCritical
End Function

'写键值
Public Function SetINIString_Zhc(strINIFileName As String, strSection As String, strKey As String, strSetString As String) As Boolean
On Error GoTo ErrorHandle
Dim iWriteLen As Integer

If Trim$(strINIFileName) <> "" And _
Trim$(strSection) <> "" And Trim$(strKey) <> "" Then
iWriteLen = WritePrivateProfileString(strSection, strKey, Trim$(strSetString), strINIFileName)
If iWriteLen <> 0 Then
SetINIString_Zhc = True
Else
SetINIString_Zhc = False
End If
Else
SetINIString_Zhc = False
End If

Exit Function
ErrorHandle:
SetINIString_Zhc = False
MsgBox ERR.Description + " SetINIString_Zhc", vbCritical
Exit Function

End Function

lingjiadong 2003-08-20
  • 打赏
  • 举报
回复
必须要用API吗,有没有简单点的方法,最好写些参考的代码给我好吗,谢谢!
laozhaoskinny 2003-08-20
  • 打赏
  • 举报
回复
http://www.china-askpro.com/msg34/qa30.shtml
http://www.china-askpro.com/msg10/qa40.shtml

7,759

社区成员

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

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