首页 » Visual Basic » VB操作ini文件的函数

VB操作ini文件的函数

WriteINI "e", "f", "DF", "c:\a.ini")  '写入
GetINI("e", "f", , "c:\a.ini") '读取

'代码,将以下代码保存为一个模块
Public 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 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
Public Function GetINI(ApplicationName As String, KeyName As String, Optional ByVal Default As String = "", Optional ByVal FileName As String = "config.ini") As String
    Dim Retval As Long
    Dim Value As String
    FileName = IIf(Mid(FileName, 2, 2) = ":\", FileName, Replace(App.Path & "\" & FileName, "\\", "\"))
    Value = Space(128)
    Retval = GetPrivateProfileString(ApplicationName, KeyName, Default, Value, Len(Value), FileName)
    GetINI = Left(Trim(Value), Len(Trim(Value)) - 1)
End Function
Public Sub WriteINI(ApplicationName As String, KeyName As String, Value As String, Optional ByVal FileName As String = "config.ini")
    Dim Retval As Long
    FileName = IIf(Mid(FileName, 2, 2) = ":\", FileName, Replace(App.Path & "\" & FileName, "\\", "\"))
    Retval = WritePrivateProfileString(ApplicationName, KeyName, Value, FileName)
End Sub

, , ,

转发到新浪微博 转发到新浪微博

目前这篇文章有4条评论(Rss)

  1. hotel valmontone | #1
    05/16/2012 at 11:59

    Wow that was odd. I just wrote an very long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyway, just wanted to say great blog!

  2. cheap | #2
    05/16/2012 at 12:25

    pXF6gm I think this is a real great article post.Thanks Again. Fantastic.

  3. www.gpsmoto.org | #3
    05/16/2012 at 13:51

    I’ve been absent for a while, but now I remember why I used to love this blog. Thank you, I’ll try and check back more often. How frequently you update your web site?

  4. zinc | #4
    05/16/2012 at 15:27

    Another very entertaining post. Ive been reading through some of your posts and finally decided to drop a comment on this one. Please feel free to visit my site Doppler

我要评论