I'm building my first application (using .vb), which is a calendar appointment app. I've created it in this manner - I have three textboxes, one each for date, time and location. The text entries from the textboxes are sent to a list box. At the listbox, I have a save button to save the entries as an appointment to a text file in a folder. I have a show appointments button to load the text file. My problem is that when I create a new appointment, the previous entry on the text file is overwritten, so I need to append the new entries in the list box to the text file saving the appointments.
What I have tried:
This is the code for the save button.
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
IO.Directory.CreateDirectory("C:\Test")
Dim w As New IO.StreamWriter("C:\Test\01.txt")
Dim i As Integer
For i = 0 To ListBox1.Items.Count - 1
w.WriteLine(ListBox1.Items.Item(i))
Next
w.Close()
End Sub
This is the entire app code.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
ListBox1.Items.Add(TextBox2.Text)
ListBox1.Items.Add(TextBox3.Text)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex())
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged, ListBox1.Click
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
IO.Directory.CreateDirectory("C:\Test")
Dim w As New IO.StreamWriter("C:\Test\01.txt")
Dim i As Integer
For i = 0 To ListBox1.Items.Count - 1
w.WriteLine(ListBox1.Items.Item(i))
Next
w.Close()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim r As IO.StreamReader
r = New IO.StreamReader("C: \Test\01.txt")
While (r.Peek() > -1)
ListBox1.Items.Add(r.ReadLine)
End While
r.Close()
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Me.TextBox1.Text = Me.DateTimePicker1.Text
End Sub
End Class