我是靠谱客的博主 活泼红牛,这篇文章主要介绍读取INI文件 ---VbCode,现在分享给大家,希望可以做个参考。

'Function to read application setting from INI file
Public Function IniFileRead(ByVal vstrINIPath As String, vstrINIFileName As String, _
    ByVal vstrINIType As String, ByRef vstrVar As String, ByVal vstrName As String) As Boolean
   
    On Error GoTo ErrHandler
   
    Dim lResult As Long
    Dim sTemp As String
    Dim lDB As Long
    Dim msIniFileFullPath As String
   
    IniFileRead = False
   
    msIniFileFullPath = vstrINIPath & "" & vstrINIFileName

    'get connection string
    sTemp = Space$(300)
    lResult = GetPrivateProfileString(vstrINIType, _
                                      vstrName, _
                                      "", _
                                      sTemp, _
                                      300, _
                                      msIniFileFullPath)
   
    If lResult < 1 Or lResult > 300 Then
        GoTo ErrHandler
    Else
        sTemp = Left(sTemp, lResult)
    End If
    vstrVar = sTemp
   
    IniFileRead = True
   
    Exit Function
ErrHandler:
    IniFileRead = False
   
End Function

调用:
IniFileRead(App.Path, mstrINIFileName, "Database", StrPwd, "Password")

app.path:INI文件存放路径
mstrINIFileName:INI文件名称

INI文件格式:
[database]
Server="aa"
DataBase="test"
UserID="sa"
Password="aa"

最后

以上就是活泼红牛最近收集整理的关于读取INI文件 ---VbCode的全部内容,更多相关读取INI文件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(116)

评论列表共有 0 条评论

立即
投稿
返回
顶部