You can use the following function.
Private Function funcGetPrivateProfileString(ByVal sKey As String, ByVal sFile As String)
Open sFile For Input As #100
Dim sLine As String
Dim strKey As String
Dim strValue As String
Dim sRetValue As String
sRetValue = ""
Dim iPos As Integer
Do While Not EOF(100)
Line Input #100, sLine
iPos = InStr(1, sLine, "=")
If iPos > 0 Then
strKey = Mid(sLine, 1, iPos - 1)
strValue = Mid(sLine, iPos + 1, Len(sLine))
If strKey = sKey Then
sRetValue = strValue
Exit Do
End If
End If
Loop
Close #100
funcGetPrivateProfileString = sRetValue
End Function
Then you can call the function as below.
strTest = funcGetPrivateProfileString("<key>", "<path to ini file>/sample.ini")
|