'====================================================================== 'Read a profile from .ini file ' ' Option Explicit Private Function GetProfile(strSection, strKey, varDefault, strPathIni) GetProfile = varDefault ' Initialize by default Dim fso : Set fso = CreateObject("Scripting.FileSystemObject") Dim f : Set f = fso.OpenTextFile(strPathIni) Dim strLine Dim fSectionFound Dim strKeyFound fSectionFound = False Do While f.AtEndOfStream <> True strLine = Trim(f.ReadLine) If (strLine <> "") And (Left(strLine, 1) <> ";") Then ' Skip Blank/Comment Line ' When Key was found If fSectionFound = True Then If strKey = Left(strLine, InStr(strLine, "=") - 1) Then GetProfile = Mid(strLine, InStr(strLine, "=") + 1) f.Close() Set fso = Nothing Exit Function ' Success End If End If ' Control inside target section or not. If (Left(strLine, 1) = "[") And (Right(strLine, 1) = "]") Then If strLine = ("[" + strSection + "]") Then fSectionFound = True Else fSectionFound = False End If End If End If Loop f.Close() Set fso = Nothing End Function