Read .ini vb 2008
Make a new module containing this:
Now you're just going to need to add a line to the start of your program. Such as:
Now create a .ini file.
As you saw before,
Readinivalue is the command it calls with the module.
"C:\data.ini" is the .ini file that you just created. Modify the path or filename as much as you want, just make sure it's the same path as the ini you created.
"data" is the header in the .ini, such as [data].
"Data1" is the value you want it to read, such as Data1=blahblahblah.
I hope this helped! +Rep me please!
Code:
Public Function ReadIniValue(ByRef INIpath As String, ByRef KEY As String, ByRef Variable As String) As String
Dim NF As Short
Dim Temp As String
Dim LcaseTemp As String
Dim ReadyToRead As Boolean
AssignVariables:
NF = FreeFile
ReadIniValue = ""
KEY = "[" & LCase(KEY) & "]"
Variable = LCase(Variable)
EnsureFileExists:
FileOpen(NF, INIpath, OpenMode.Binary)
FileClose(NF)
SetAttr(INIpath, FileAttribute.Archive)
LoadFile:
FileOpen(NF, INIpath, OpenMode.Input)
While Not EOF(NF)
Temp = LineInput(NF)
LcaseTemp = LCase(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 & "="))
FileClose(NF) : Exit Function
End If
End If
End While
FileClose(NF)
End Function
Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
YourLabelHere.Text = ReadIniValue("C:\data.ini", "data", "Data1") 'replace yourlabelhere with a label or textbox
End Sub
Code:
[data] data1=Whatever you want it to read //Use two backslashes for comments
Code:
ReadIniValue("C:\data.ini", "data", "Data1")
"C:\data.ini" is the .ini file that you just created. Modify the path or filename as much as you want, just make sure it's the same path as the ini you created.
"data" is the header in the .ini, such as [data].
"Data1" is the value you want it to read, such as Data1=blahblahblah.
I hope this helped! +Rep me please!