2

hello i am using this code to save listbox1 contents to .txt document it works. but as soon i reopen the program and save new text it overwriting original text how can i make it add as an additional text rather then overwriting. thank you so much every 1.

Dim W As IO.StreamWriter
Dim i As Integer
W = New IO.StreamWriter("C:\test\test.txt")

For i = 0 To ListBox2.Items.Count - 1
    W.WriteLine(ListBox2.Items.Item(i))
Next
W.close()
Tim
  • 28,212
  • 8
  • 63
  • 76
user2581791
  • 43
  • 1
  • 4
  • 11

2 Answers2

3

Try this

W = New IO.StreamWriter("C:\test\test.txt", True)

The true statement indicates that you want to append text to an existing file.

D_Bester
  • 5,723
  • 5
  • 35
  • 77
-1

This is great!

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

Dim count As Integer = System.IO.File.ReadAllLines("location").Length
    If count <= 9 Then
        MsgBox("less then 10")
    Else
        MsgBox("more then 10")
    End If
End Sub
Jeff
  • 1