我有个INI文件如下:
[Config]
inter=[pp]
abc=
def=请问我如果想把abc= def=  改为:bbb=  ddd=
该怎么写这段程序,我现在主要的难点在如何找到[pp]这个字段,
而且如何在改了abc= 为 bbb= 后怎么定位到下一行   

解决方案 »

  1.   

    http://www.china-askpro.com/msg34/qa30.shtml
    http://www.china-askpro.com/msg10/qa40.shtml
      

  2.   

    必须要用API吗,有没有简单点的方法,最好写些参考的代码给我好吗,谢谢!
      

  3.   


    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
      

  4.   

    用改文本文件的Open方法不行么?