SolvedSave File .INI Source Code

Posts 115 of 15 · Page 1 of 1
Save File .INI Source Code
the title say it all ?

Like in PerX ? any one can help please because i want to make a advance injector


Heres my example
Either that or use XML... and not inis
can you help me ?

my problem is i cant Load my ListBox i use this to save my settings -> http://www.mpgh.net/forum/33-visual-...-settings.html

Heres my Code
Red Color Contains = Error


Code:
  Private Sub SaveInformation()
        'Write the form "title" to section "General"
        inifile.WriteValue("General", "Process ", txtText.Text)
        inifile.WriteValue("General", "Quit ", chkBox1.Checked)
        inifile.WriteValue("General", "ListBox", ListBox1.Items.Count)
    End Sub

    Private Sub LoadInformation()
        'Read the form "title" of the section "General"
        txtText.Text = inifile.ReadValue("General", "Process ", "")
        chkBox1.Checked = inifile.ReadValue("General", "Quit ", "")
        ListBox1.Items.Count = inifile.ReadValue("General", "Quit ", "")
    End Sub


---------- Post added at 09:42 AM ---------- Previous post was at 09:38 AM ----------

Quote Originally Posted by Hassan View Post
Or you could use Jason's library for reading and writing .INI files:

http://www.mpgh.net/forum/27-coders-...e-parsing.html

The highlight tag fucked up the code. Hopefully you can figure out the right code for yourself.
thanks but the code is for C# i want code from VB Thanks for the help
You do realize that ListBox1.Items.Count is ReadOnly right? which means you cant edit it.

Also, the reason .NET devs did not include a Library for INI files is because they want YOU to use XML. If so, why no using it? meh..
Sigh. Replace the red line of your code to this:

Code:
ListBox1.Items.Add(inifile.ReadValue("General", "Quit ", ""))
Something like:
Code:
For Each Opti As String In File.ReadAllLines("Path of file") 'Reads all the lines from the File

Dim TempStr As String = Opti 'Makes a new String Temp Valu. (Maybe not needed tho :P)
TempStr.Remove(0, TempStr.IndexOf("=")) 'Removes text until it finds: = (You might have to add: TempStr.IndexOf("=") + 1
ListBox1.Items.Add(TempStr) 'Adds the Value to the listbox

Next
I might have done it a bit wrong or so.
But I suppose you can see the point here.
Quote Originally Posted by Jorndel View Post
Something like:
Code:
For Each Opti As String In File.ReadAllLines("Path of file") 'Reads all the lines from the File

Dim TempStr As String = Opti 'Makes a new String Temp Valu. (Maybe not needed tho :P)
TempStr.Remove(0, TempStr.IndexOf("=")) 'Removes text until it finds: = (You might have to add: TempStr.IndexOf("=") + 1
ListBox1.Items.Add(TempStr) 'Adds the Value to the listbox

Next
I might have done it a bit wrong or so.
But I suppose you can see the point here.
Code:
TempStr.Remove(0, TempStr.IndexOf("="))
This line doesn't affects TempStr. You gotta assign TempStr the value which is returned after the Remove function is called. Also, you're getting the index of is euqal to sign '='. The Remove function removes everything excluding the character that resides on that index. So you gotta add the = sign by incrementing the count by 1.

Code:
TempStr = TempStr.Remove(0,TempStr.IndexOf("=") + 1)
Anyways, I added a couple of checks. Here's another version that can work for you:

Code:
Dim INIFile As String = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\INI.ini"
For Each Line As String In File.ReadAllLines(INIFile)
    If Not Line.Trim().StartsWith("[") And Not Line.Trim().EndsWith("]") And Line.Contains("=") Then
         Dim SettingName As String = Line.Substring(0, Line.IndexOf("="))
         Dim SettingValue As String = Line.Substring(Line.IndexOf("=") + 1)
         ListBox1.Items.Add(SettingValue)
    End If
Next
Yeah, forgot to assign the new value :P
Getting older by each day
Protip: Use XML instead of INI files.
Quote Originally Posted by Broderick View Post
Protip: Use XML instead of INI files.
Oldtip... ._.
Quote Originally Posted by 'Bruno View Post
Oldtip... ._.
Shaddup Bruno.
Quote Originally Posted by Broderick View Post


Shaddup Bruno.
Jason, stop going off topic pls ._.
Quote Originally Posted by Hassan View Post


Jason, stop going off topic pls ._.
I wouldn't have had to, but then Bruno had to indulge in his tendency to flame n00bs.
Posts 115 of 15 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?