Read .ini vb 2008

Posts 1–4 of 4 · Page 1 of 1
Read .ini vb 2008
Make a new module containing this:

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
Now you're just going to need to add a line to the start of your program. Such as:

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
Now create a .ini file.

Code:
[data]
data1=Whatever you want it to read
//Use two backslashes for comments
As you saw before,

Code:
ReadIniValue("C:\data.ini", "data", "Data1")
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!
This is Leeched, Just give credit where it is do...

Code:
Option Explicit
'Untuk membaca isi ini file
Public Function ReadIniValue(INIpath As String, KEY As String, 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:
    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$(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
No +1 Rep or thanks for leeching, and not giving credit.

If you want to know why I bothered looking to see if it was leeched, Main reason is because you posted a tutorial for vb.net 2008, then after that you asked where to download vb.net 2008.........

How much can you know if you can't use google?
wait vb 2008 is vb.net?

damn i am stupid

STUPID

By the way nextgen, this isnt all leeched. I edited for errors I got with vb 2008

this was actually a vb6 tutorial before.. 'kay?
VB 7 - 10 is ".net"

And Yes, it's still leeched, just in your post, edit it and say

Converted from vb6 - VB 2008
Original Source By
Edit By

Etc.

Just as you would if converting source from C++ to VB.net Recently I did a project and had to convert C++ to VB.net, Only one person would see this, and that person knows almost nothing about coding, and I still in the code and in the software marked it, Code Concept by: ******** , Original Code by ******** Modified to work with VB and Modified to work with Patch By: Nextgen1

Get the idea?
Posts 1–4 of 4 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?