Question
Need help with these questions for visual basic. A sub is created and utilized to be called to refresh the listbox each time there is
Need help with these questions for visual basic.
A sub is created and utilized to be called to refresh the listbox each time there is a file change along with the determination of the count.
When the user clicks on Create file, the user will be presented with an input box to enter a name of a file. A try/catch is utilized to make sure a name is entered. If successful the program creates a blank file and displays the blank file in the textbox. The count is updated.
Public Class FrmMemberList Dim textfile As String Private Sub mnuExit_Click(sender As Object, e As EventArgs) Handles mnuExit.Click Me.Close() End Sub
Private Sub mnuload_Click(sender As Object, e As EventArgs) Handles mnuload.Click OpenFileDialog1.ShowDialog() textfile = OpenFileDialog1.FileName LstDisplay.DataSource = IO.File.ReadAllLines(textfile) LstDisplay.SelectedItem = Nothing
End Sub
Private Sub mnuascending_Click(sender As Object, e As EventArgs) Handles mnuascending.Click Dim ascendingquery = From members In IO.File.ReadLines(textfile) Order By members Ascending Select members LstDisplay.DataSource = ascendingquery.ToList()
End Sub
Private Sub mnudescending_Click(sender As Object, e As EventArgs) Handles mnudescending.Click Dim ascendingquery = From members In IO.File.ReadLines(textfile) Order By members Descending Select members LstDisplay.DataSource = ascendingquery.ToList()
End Sub
Private 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() LstDisplay.DataSource = Nothing LstDisplay.DataSource = IO.File.ReadAllLines(textfile)
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).ToList() IO.File.WriteAllLines(textfile, deletquery.AsEnumerable())
LstDisplay.DataSource = Nothing LstDisplay.DataSource = IO.File.ReadAllLines(textfile)
End Sub
Private Sub mnucreate_Click(sender As Object, e As EventArgs) Handles mnucreate.Click Dim nametocreate = InputBox("Please enter a name of the file to create.") textfile = nametocreate & ".txt" If Not IO.File.Exists(textfile) Then Dim sw As IO.StreamWriter = IO.File.CreateText(textfile) sw.Close()
End If LstDisplay.DataSource = Nothing LstDisplay.DataSource = IO.File.ReadAllLines(textfile)
End Sub
Private Sub txtCount_TextChanged(sender As Object, e As EventArgs) Handles txtCount.TextChanged
End Sub End Class
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