Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Visual Basic Create a program that allows a user to create, edit and save

ID: 3579080 • Letter: U

Question

Using Visual Basic

Create a program that allows a user to create, edit and save phonebook data. The program should contain textboxes for a first name, last name, and phone number. It should also contain a Load Data and Save Data button. All data should be stored in a comma delimited text file using the format “firstname, lastname, phonenumber”. When the Load Data button is pressed, the program should check for the existence of the data file. If the data file exists it should be read and its contents should be displayed on the form. When the Save Data button is pressed the program should write the first name, last name and phone number from the form into a file.

Explanation / Answer

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        Dim item As String = TextBox1.Text.ToString()

        Dim index As Integer = ListBox1.FindString(item)

  

        If index = -1 Then

            ListBox1.SelectedIndex = ListBox1.SelectedIndex

        Else

            ListBox1.SetSelected(index, True)

        End If

    End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Form2.Show()

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try

            For Each Name As String In My.Settings.Names

                ListBox1.Items.Add(Name)

            Next

        Catch ex As Exception

        End Try

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If ListBox1.SelectedIndex < 0 Then

        Else

            Dim ask As MsgBoxResult

            ask = MsgBox("Are you sure you want to remove " & ListBox1.SelectedItem & " ?", MsgBoxStyle.YesNo)

            If ask = MsgBoxResult.Yes Then

                My.Settings.Names.Remove(ListBox1.SelectedItem)

                My.Settings.Save()

                ListBox1.Items.Clear()

                For Each Name As String In My.Settings.Names

                    ListBox1.Items.Add(Name)

                Next

            ElseIf ask = MsgBoxResult.No Then

  

            End If

        End If

    End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Me.Close()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        If My.Settings.Names Is Nothing Then

            If TextBox1.Text = "" Or TextBox2.Text = "" Then

                MsgBox("Must Fill all Fields")

            Else

                My.Settings.Names.Add(TextBox1.Text + " - " + TextBox2.Text)

                My.Settings.Save()

                Me.Close()

            End If

        Else

            If TextBox1.Text = "" Or TextBox2.Text = "" Then

                MsgBox("Must Fill all Fields")

            Else

                My.Settings.Names.Add(TextBox1.Text + " - " + TextBox2.Text)

                My.Settings.Save()

                Me.Close()

  

            End If

  

        End If

        TextBox1.Clear()

        TextBox2.Clear()

        Form1.ListBox1.Items.Clear()

        For Each Name As String In My.Settings.Names

            Form1.ListBox1.Items.Add(Name)

        Next

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        If My.Settings.Names Is Nothing Then

            If TextBox1.Text = "" Or TextBox2.Text = "" Then

                MsgBox("Must Fill all Fields")

            Else

                My.Settings.Names.Add(TextBox1.Text + " - " + TextBox2.Text)

                My.Settings.Save()

                Me.Close()

            End If

        Else

            If TextBox1.Text = "" Or TextBox2.Text = "" Then

                MsgBox("Must Fill all Fields")

            Else

                My.Settings.Names.Add(TextBox1.Text + " - " + TextBox2.Text)

                My.Settings.Save()

                Me.Close()

  

            End If

  

        End If

        TextBox1.Clear()

        TextBox2.Clear()

        Form1.ListBox1.Items.Clear()

        For Each Name As String In My.Settings.Names

            Form1.ListBox1.Items.Add(Name)

        Next

End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote