広告
広告
Iniファイルの内容を抽出する関数 数値、文字列両対応版
第一引数 | INIファイルフルパス(String) |
---|---|
第二引数 | セクション名(String) |
第三引数 | Key名(String) |
第四引数 | 取得失敗時の戻り値(String) |
第五引数 | True:文字列 / False:数値(Boolean) |
戻り値 | 結果(Variant) |
Option Compare Database Public Declare Function GetPrivateProfileInt Lib "kernel32" _ Alias "GetPrivateProfileIntA" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As String, _ ByVal nDefault As Long, _ ByVal lpFileName As String) As Long 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 Function ReadIni(strIni As String, strSec As String, strKey As String, _ strDef As String, blnStr As Boolean) As Variant If blnStr Then ReadIni = ReadStr(strIni, strSec, strKey, strDef) Else If Not IsNumeric(strDef) Then strDef = "0" End If ReadIni = GetPrivateProfileInt(strSec, strKey, CLng(strDef), strIni) End If End Function Public Function ReadStr(ByVal strFileIni As String, ByVal strSectName As String, _ ByVal strKeyName As String, ByVal strDefault As String) As String Dim lngRtn As Long Dim strRtn As String strRtn = Space$(256) lngRtn = GetPrivateProfileString(strSectName, strKeyName, strDefault, strRtn, 255, strFileIni) If lngRtn > 0 Then ReadStr = strRtn Else ReadStr = strDefault End If End Function
広告