Hi guys, I'm trying to make something like settings part of my app but I'm stuck here:
I want to add text from textbox1.text to the first line of text file, textbox2.text to second line etc.
This is my code so far, but it only overwrite the line if line exist.
Code:
Public Class Form2
Dim Settings As String = IO.Path.Combine(Application.StartupPath, "Options.ini")
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lines() As String = IO.File.ReadAllLines(Settings)
TextBox1.Text = lines(0)
TextBox2.Text = lines(1)
TextBox3.Text = lines(2)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using FD As New OpenFileDialog()
FD.Filter = "exe files (*.exe)|*.exe|All files (*.*)|*.*"
If FD.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim r = New IO.StreamReader(FD.FileName)
TextBox1.Text = FD.FileName
Dim lines() As String = System.IO.File.ReadAllLines(Settings)
lines(0) = TextBox1.Text
System.IO.File.WriteAllLines(Settings, lines)
End If
End Using
End Sub
End Class