I'm posting this new thread because i finally fixed my code and all thats left for me to do is to create a search button. In my last post nobody really gave me any advice, so i figured i would try to explain this in the most simplest way: I'm just trying to create a search button and i need help doing it. I am a beginner. I just want the program to ask the user what he would like to search for, when the search button is clicked on. when the user types in the word he wants to search for.....i want the program to look in the text file to see if that word exists and if the word exists i want that word to appear in my listbox. I am studying trimester. so i have not been going to class for 4 months i have been going for almost 2 we have not discussed findstring or findstringexact. I looked up info on them but i dont know how to use them correctly with streamreader i think i have to create a new string but i get confused because i am a beginner. if you could be able to help me i would be extremely grateful. If not thank you for taking the time to look at my post. Here is my code so far, if you see anything wrong with what i have written so far feel free to give me some advice to make it better. Thank you. (I have not created a search button):
Code:
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim archive As StreamWriter = New StreamWriter("stuff.txt", True)
ListBox1.Items.Add(TextBox1.Text)
ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
archive.WriteLine(TextBox1.Text)
archive.Close()
MsgBox("ok")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim archive As StreamReader = New StreamReader("stuff.txt", True)
ListBox1.Items.Clear()
While archive.Peek() > -1
ListBox1.Items.Add(archive.ReadLine)
End While
archive.Close()
End Sub
Public Sub DeleteLine(ByRef fileaddress As String, ByRef listbox1_selecteditem As String)
Dim thefilelines As New List(Of String)
thefilelines.AddRange(File.ReadAllLines(fileaddress))
thefilelines.Remove(listbox1_selecteditem)
File.WriteAllLines(fileaddress, thefilelines.ToArray)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
DeleteLine("product.txt", ListBox1.SelectedItem)
ListBox1.Items.Remove(ListBox1.SelectedItem)
MsgBox("Item Deleted")
End Sub
End Class