GetPrivateProFileString:可以读取自定义的INI文件。
WriteprivateProFileString:可以写入自定义的INI文件。
具体可通过API浏览器进行查找。

解决方案 »

  1.   

    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 Sub Form_Load()
        ''KPD-Team 1999
        ''URL: http://www.allapi.net/
        ''E-Mail: [email protected]
        Dim Ret As String, NC As Long
        ''Write the setting to the file (c:\test.ini) under
        ''   Project1 -> Keyname
        WritePrivateProfileString App.Title, "KeyName", "This is the value", "c:\test.ini"
        ''Create a buffer
        Ret = String(255, 0)
        ''Retrieve the string
        NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
        ''NC is the number of characters copied to the buffer
        If NC <> 0 Then Ret = Left$(Ret, NC)
        ''Show our string
        MsgBox Ret
        ''Delete the file
        Kill "c:\test.ini"
    End Sub
      

  2.   

    我写的函数Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, lpKeyName As Any, ByVal lpDefault As String, ByVal lpRetunedString 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 lplFileName As String) As LongFunction GetFromINI(AppName As String, KeyName As String) As String
       Dim RetStr As String
       
       RetStr = String(255, Chr(0))
       GetFromINI = Left(RetStr, GetPrivateProfileString(AppName, ByVal KeyName, "", RetStr, Len(RetStr), INIFILE HERE))
    End FunctionSub WriteToIni(AppName As String, KeyName As String, KeyValue as String)
    WritePrivateProfileString AppName, KeyName, KeyValue, INIFILE HERE
    End Sub
      

  3.   

    我也来一段:
    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 Sub WriteToIni(ByVal Filename As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
        Dim buff As String * 128
        buff = Value + Chr(0)
        WritePrivateProfileString Section, Key, buff, Filename
    End Sub
    Private Function ReadFromIni(ByVal Filename As String, ByVal Section As String, ByVal Key As String) As String
        Dim i As Long
        Dim buff As String * 128
        GetPrivateProfileString Section, Key, "", buff, 128, Filename
        i = InStr(buff, Chr(0))
        ReadFromIni = Trim(Left(buff, i - 1))
    End Function
      

  4.   

    这是我在我的程序中一直都运行得很好的,如果不行再找我!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 LongPublic Function read_ini(sINIfile As String, sSection As String, sKey As String, sDefault As String) As String
    On Error GoTo err_msg
        Dim sTemp As String * 256
        Dim nLength As Integer
        
        sTemp = Space$(256)
        nLength = GetPrivateProfileString(sSection, sKey, sDefault, sTemp, _
                256, sINIfile)
        read_ini = Left$(sTemp, nLength)
    Exit Function
    err_msg:
        MsgBox "Read system ini.file is wrong!", vbInformation + vbOKOnly, "system error!"
    End FunctionPublic Sub write_ini(sINIfile As String, sSection As String, sKey As String, sValue As String)
    On Error GoTo err_msg
        Dim n As Integer
        Dim sTemp As String
        sTemp = sValue
        For n = 1 To Len(sValue)
            If Mid$(sValue, n, 1) = vbCr Or Mid$(sValue, n, 1) = vbLf Then _
              Mid$(sValue, n) = ""
        Next n
        n = WritePrivateProfileString(sSection, sKey, sTemp, sINIfile)
    Exit Sub
    err_msg:
        MsgBox "write system ini.file is wrong!", vbInformation + vbOKOnly, "system error!"
    End Sub