zoukankan      html  css  js  c++  java
  • 读取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"

  • 相关阅读:
    渡一 5-1、2 条件语句补充,初识引用值,typeof,类型转换
    渡一 3-2 js基础知识
    渡一 25 正则表达式
    渡一 15-1 数组去重(上下)
    渡一 14-3 数组,类数组
    渡一 14-1&2 三目运算符,数组,类数组
    3_Guess Fingers
    2_Cat Years
    27_Blog Reader
    26_Json_Example
  • 原文地址:https://www.cnblogs.com/kentyshang/p/425774.html
Copyright © 2011-2022 走看看