使用open打开你的ini文件
用write写
查看帮助有

解决方案 »

  1.   

    看你的INI文件是什么格式了,如果是你自己定义的可以用open,write 了!如果是标准的INI文件,最好还是用API来做了,API中有专门用来写INI文件的函数(GetPrivateProfileString,WritePrivateProfileString),用来写INI最好不过了!
      

  2.   

    open filename for input as #1
    while eof(1)
    line input #1,变量
    wend
    close #1
      

  3.   

    open filename for input as #1
    while eof(1)
    line input #1,bianliang
    wend 
    close #1
      

  4.   

    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 Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, 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 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 Property Get KeyValueOfIni(ByVal strIniFile As String, ByVal strSec As String, _
                                ByVal strKey As String, ByVal strDef As String) As String
        Dim lSize As Long
        Dim sResult As String
        Dim lLeft As Long
        
        sResult = String(LONGSTR, vbNullChar)
        lSize = GetPrivateProfileString(strSec, strKey, strDef, sResult, LONGSTR, strIniFile)
        lLeft = InStr(sResult, vbNullChar) - 1
        If lLeft > 0 Then
            lSize = lLeft
        End If
        If lSize <> 0 Then
            KeyValueOfIni = Left(sResult, lSize)
        Else
            KeyValueOfIni = ""
        End If
        sResult = ""
    End Property
    Public Property Let KeyValueOfIni(ByVal strIniFile As String, ByVal strSec As String, _
                                    ByVal strKey As String, ByVal strDef As String, ByVal Value As String)
        If strDef <> Value Then
            Call WritePrivateProfileString(strSec, strKey, Value, strIniFile)
        End If
    End PropertyPublic Property Get SectionKeysValues(ByVal strIniFile As String, ByVal strSec As String)
        Dim lSize As Long
        Dim sResult As String
        Dim a() As String, a1() As String
        Dim I As Integer, J As Integer, K As Integer
        
        sResult = String(LONGSTR * 4, 0)
        lSize = GetPrivateProfileSection(strSec, sResult, LONGSTR * 4, strIniFile)
        If lSize <> 0 Then
            sResult = Left(sResult, lSize - 1)
            For I = Len(sResult) To 1 Step -1
                If Mid(sResult, I, 1) <> vbNullChar Then
                    Exit For
                End If
            Next I
            sResult = Left(sResult, I)
            a = Split(sResult, vbNullChar)
            I = UBound(a)
            ReDim a1(I, 1)
            For I = 0 To I
                J = InStr(a(I), "=")
                K = Len(a(I))
                a1(I, 0) = Left(a(I), J - 1)
                a1(I, 1) = Right(a(I), K - J)
            Next I
            SectionKeysValues = a1
            Erase a, a1
        End If
    End Property
    Public Property Let SectionKeysValues(ByVal strIniFile As String, ByVal strSec As String, ArraySettings)
        Dim strT As String, I As Integer
        
        strT = ""
        For I = 0 To UBound(ArraySettings)
            strT = strT & ArraySettings(I, 0) & "=" & ArraySettings(I, 1) & vbNullChar
        Next I
        strT = strT & vbNullChar
        Call WritePrivateProfileSection(strSec, strT, strIniFile)
        strT = ""
    End Property
      

  5.   

    这里有一个现成的:
    Public Sub ReadIniFile()    On Error Resume Next    Dim strSQL, strLine As String
        Dim tmpS() As String
        Dim FileNumber As Integer
        If Dir(App.Path & "\setuplist.ini") = "" Then
            gSQLServer = ""
            gDataBase = ""
            gLogin = ""
            gPassword = ""
            Exit Sub
        End If
        
        FileNumber = FreeFile
        Open App.Path & "\setuplist.Ini" For Input As #FileNumber
        Do While Not EOF(FileNumber)
            Line Input #FileNumber, strLine
            tmpS = Split(strLine, "=")
            Select Case UCase(Trim(tmpS(0)))
                Case "SQL SERVER"
                    gSQLServer = Trim(tmpS(1))
                Case "DATABASE"
                    gDataBase = Trim(tmpS(1))
                Case "LOGIN"
                    gLogin = Trim(tmpS(1))
                Case "PASSWORD"
                    gPassword = Trim(tmpS(1))
            End Select
        Loop
        Close #FileNumber
        
    End Sub