Advertisement
Guest User

INI Reading.

a guest
Mar 23rd, 2012
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.58 KB | None | 0 0
  1. Module mod_IniReader
  2.     ''' <summary>
  3.     ''' Credits: xblackbondx > http://www.forbiddencheats.net/forum/showthread.php?7801-Read-ini-vb-2008
  4.     ''' </summary>
  5.     ''' <param name="INIpath">Path To Ini File</param>
  6.     ''' <param name="KEY">Section in INI file. EG: [Section]</param>
  7.     ''' <param name="Variable">Variable to read. EG: varname=value</param>
  8.     ''' <returns>INI Variable Value</returns>
  9.     ''' <remarks></remarks>
  10.     Public Function ReadIniValue(ByRef INIpath As String, ByRef KEY As String, ByRef Variable As String) As String
  11.         Dim NF As Short
  12.         Dim Temp As String
  13.         Dim LcaseTemp As String
  14.         Dim ReadyToRead As Boolean
  15.  
  16. AssignVariables:
  17.         NF = FreeFile()
  18.         ReadIniValue = ""
  19.         KEY = "[" & LCase(KEY) & "]"
  20.         Variable = LCase(Variable)
  21.  
  22. EnsureFileExists:
  23.         FileOpen(NF, INIpath, OpenMode.Binary)
  24.         FileClose(NF)
  25.         SetAttr(INIpath, FileAttribute.Archive)
  26.  
  27. LoadFile:
  28.         FileOpen(NF, INIpath, OpenMode.Input)
  29.         While Not EOF(NF)
  30.             Temp = LineInput(NF)
  31.             LcaseTemp = LCase(Temp)
  32.             If InStr(LcaseTemp, "[") <> 0 Then ReadyToRead = False
  33.             If LcaseTemp = KEY Then ReadyToRead = True
  34.             If InStr(LcaseTemp, "[") = 0 And ReadyToRead = True Then
  35.                 If InStr(LcaseTemp, Variable & "=") = 1 Then
  36.                     ReadIniValue = Mid(Temp, 1 + Len(Variable & "="))
  37.                     FileClose(NF) : Exit Function
  38.                 End If
  39.             End If
  40.         End While
  41.         FileClose(NF)
  42.     End Function
  43. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement