View Single Post
Old September 3rd, 2004, 06:04 AM
madhukp madhukp is offline
Friend of Wrox
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp

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
Close #100
funcGetPrivateProfileString = sRetValue
End Function

Then you can call the function as below.

strTest = funcGetPrivateProfileString("<key>", "<path to ini file>/sample.ini")