Public Function ReadIniValue(ByVal INIpath As String, ByVal KEY As String, ByVal Variable As String) As String
Dim NF As Integer
Dim temp As String
Dim LcaseTemp As String
Dim ReadyToRead As Boolean
AssignVariables:
NF = FreeFile
ReadIniValue = ""
KEY = "[" & LCase$(KEY) & "]"
Variable = LCase$(Variable)
EnsureFileExists:
If Dir(INIpath) = "" Then
MsgBox " No file you are tring to read ", vbOKOnly, "Error"
Exit Function
End If
'Open INIpath For Binary As NF
' Close NF
'SetAttr INIpath, vbArchive
LoadFile:
Open INIpath For Input As NF
While Not EOF(NF)
Line Input #NF, temp
LcaseTemp = LCase$(Trim(temp))
If InStr(LcaseTemp, "[") <> 0 Then ReadyToRead = False
If LcaseTemp = KEY Then ReadyToRead = True
If InStr(LcaseTemp, "[") = 0 And ReadyToRead = True Then
If InStr(LcaseTemp, Variable & "=") = 1 Then
ReadIniValue = Mid$(temp, 1 + Len(Variable & "="))
Close NF: Exit Function
End If
End If
Wend
Close NF
End Function
Sunday, March 25, 2012
Read ini value
Function for read a value of each key from ini file.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment