读取INI配置文件

config.ini文件

[System]
Ttype=False
TMode=0
TErrMode=1
SaveTemp=0
TControl=0
Password=sa
LoadMax=1000

LoadMin=-1000

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 GetIniStr(ByVal AppName As String, ByVal In_Key As String, iniFileName As String) As String
    On Error GoTo GetIniStrErr
    If VBA.Trim(In_Key) = "" Then
        GoTo GetIniStrErr
    End If
    Dim GetStr As String
    GetStr = VBA.String(128, 0)
    GetPrivateProfileString AppName, In_Key, "", GetStr, 256, iniFileName
    GetStr = VBA.Replace(GetStr, VBA.Chr(0), "")
    If GetStr = "" Then
        GoTo GetIniStrErr
    Else
        GetIniStr = GetStr
        GetStr = ""
    End If
    Exit Function
GetIniStrErr:
    Err.Clear
    GetIniStr = ""
    GetStr = ""
End Function


'
Public Function WriteIniStr(ByVal AppName As String, ByVal In_Key As String, ByVal In_Data As String, iniFileName As String) As Boolean
    On Error GoTo WriteIniStrErr
    WriteIniStr = True
    If VBA.Trim(In_Data) = "" Or VBA.Trim(In_Key) = "" Or VBA.Trim(AppName) = "" Then
        GoTo WriteIniStrErr
    Else
        WritePrivateProfileString AppName, In_Key, In_Data, iniFileName
    End If
    Exit Function
WriteIniStrErr:
    Err.Clear
    WriteIniStr = False
End Function

 

 

Dim loadMax As Double dim LoadMin as double   IniFilePath = App.Path & "\SystemIni.ini"    
 loadMax = GetIniStr("System", "LoadMax", IniFilePath)    ''1000 LoadMin = GetIniStr("System", "LoadMin", IniFilePath)      ''-1000

 

上一篇:语录小程序怎样制作


下一篇:VB2010(1)_heloo the world!