I've written a small winform app in vb.net 2003... The idea is to type into textbox and click stamp button.. the text entry appears into a Listbox and a text file with name from the textbox is created. If the Listbox Item is selected... it will delete the text file from its location.
1. Type a word into Textbox1
2. click Button1
3. Textbox1 value appears in Listbox1
4. A file is created 'c:\Jobs\Textbox name.txt'
1. Listbox1 Item is selected
2. Label99.Text = ListBox1.SelectedItem
3. Button2 is clicked & text file 'c:\Jobs\Textbox name.txt' is deleted!
I know my code sucks... I'm still only p/t with vb. I'm sure I'm over compensating.
Most of the code works except the delete text file part. Can an expert please advise were I'm going wrong. Please see my code.
Dim FileToDel As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'click button and text in textbox1 appears in Listbox1 as well as creates a txt file 'textbox1.data.text'!
If TextBox1.Text = "" Then
Dim iWsave As System.IO.StreamWriter
iWsave = File.AppendText("C:\Users\bob\Documents\" & TextBox1.Text & ".txt")
iWsave.WriteLine(TextBox1.Text & ";" & ComboBox1.Text & ";" & ComboBox2.Text)
Catch ex As Exception
MsgBox("Error code 10, Contact your Administrator!")
TextBox1.Text = ""
ComboBox1.Text = "P?"
ComboBox2.Text = " ..."
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Select Listbox1 item, not only removes the items but should delete the txt file too!
Do Until ListBox1.SelectedItems.Count = 0
FileToDel = "C:\Users\bob\Documents\" & Label99.Text & ".txt"
If System.IO.File.Exists(FileToDel) = True Then
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Label99.Text = ListBox1.SelectedItem