Question
Visual basic help 9. When the user clicks on the Delete Member, the application will verify with an if statement if a name is selected
Visual basic help 9. When the user clicks on the Delete Member, the application will verify with an if statement if a name is selected in the listbox. If a name is not selected the user is presented with an error message and the program quits. If a name is selected, the name is removed from the file and the listbox is refreshed with the new file along with the count being updated. I have started this code but it is not working. rivate Sub mnuadd_Click(sender As Object, e As EventArgs) Handles mnuadd.Click Dim newmember As String = InputBox("Please enter a new member.") Dim sw As IO.StreamWriter = IO.File.AppendText(textfile) sw.WriteLine(newmember) sw.Close() Try sw = IO.File.AppendText(textfile) sw.WriteLine(newmember) sw.Close() LstDisplay.DataSource = Nothing LstDisplay.DataSource = IO.File.ReadAllLines(textfile) Catch exc As System.ArgumentNullException MessageBox.Show("Try again") End Try End Sub Private Sub mnudelete_Click(sender As Object, e As EventArgs) Handles mnudelete.Click If LstDisplay.SelectedIndex = -1 Then MessageBox.Show("Please select a member to be deleted") Return End If Dim deletemember As String = LstDisplay.SelectedItem Dim deletquery = From members In IO.File.ReadLines(textfile) Where members <> deletemember Select members IO.File.WriteAllLines(textfile, deletquery) LstDisplay.DataSource = Nothing LstDisplay.DataSource = IO.File.ReadAllLines(textfile) End Sub
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started