Question: I can not fix this error. It is in red below. All my forms are listed on the screenshot. I need it to open and

I can not fix this error. It is in red below. All my forms are listed on the screenshot. I need it to open and add a new contact in a separate form but the code breaks as soon as I hit the add button.

I can not fix this error. It is in red below. All

Here is formAddressBook.vb code

Imports AddNew.address

Public Class formAddressBook

Public AddressList As New Collection 'The updateListBox procedure updates the contents of the list box. Private Sub UpdateListBox() 'Clear the listbox. ListBxDisplay1.Items.Clear() 'Load the ID numbers in the collection into the list box. Dim a As AddNew.address.Address For Each a In AddressList ListBxDisplay1.Items.Add(a.Name) Next 'select the first item in the list. If ListBxDisplay1.Items.Count > 0 Then ListBxDisplay1.SelectedIndex = 0 End If End Sub

Private Sub ButAdd_Click(sender As Object, e As EventArgs) Handles ButAdd.Click 'Create an instance of the AddNew form. Dim frmAddNew As New AddNew AddNew.Show() frmAddNew.ShowDialog() Try AddressList.Add(frmAddNew.objStudent, frmAddNew.objStudent.Name) Catch ex As Exception End Try UpdateListBox() End Sub 'Remove button function.

Private Sub ButRemove_Click(sender As Object, e As EventArgs) Handles ButRemove.Click Dim intIndex As Integer 'Mak sure an item is selected. If ListBxDisplay1.SelectedIndex -1 Then 'confirm that the user wants to remove the item. If MessageBox.Show("Are You sure?", "Confirm Deletion", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then 'Rtrive the student's data from the collection. intIndex = ListBxDisplay1.SelectedIndex Try 'Remove the selected item from the collection. AddressList.Remove(ListBxDisplay1.SelectedItem.ToString()) 'update the list box. UpdateListBox() Catch ex As Exception 'Error message. MessageBox.Show(ex.Message) End Try End If End If End Sub

Private Sub ButEdit_Click(sender As Object, e As EventArgs) Handles ButEdit.Click If ListBxDisplay1.SelectedIndex -1 Then

Dim st As New Address st = AddressList.Item(ListBxDisplay1.SelectedItem.ToString()) frmAddNew.txtName.Text = st.Name frmAddNew.txtMail.Text = st.EMail frmAddNew.txtPhone.Text = st.Phone frmAddNew.rtbNotes.Text = st.Comments frmAddNew.ShowDialog() AddressList.Remove(st.Name) AddressList.Add(frmAddNew.objStudent, frmAddNew.objStudent.Name) UpdateListBox() End If End Sub

Private Sub ButExit_Click(sender As Object, e As EventArgs) Handles ButExit.Click Application.Exit() End Sub End Class

Here is AddNew.vb code

Public Class AddNew Public objStudent As New address

Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButOkAddNew.Click 'Get data from the form into the object. objStudent.Name = TxtBxNameAddNew.Text objStudent.Phone = TxtBxPhoneAddNew.Text objStudent.EMail = TxtBxEmailAddressAddNew.Text objStudent.Comments = ListBxAddNew.Text ClearForm() Me.Close() End Sub 'The clearForm procedure clears the form. Public Sub ClearForm() 'Clear the text boxes. TxtBxEmailAddressAddNew.Clear() TxtBxNameAddNew.Clear() TxtBxPhoneAddNew.Clear() ListBxAddNew.ClearSelected() 'Reset the focus. TxtBxNameAddNew.Focus() End Sub Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButCloseAddNew.Click 'Create an instance of the Main Form form. Me.Close() End Sub End Class

Here is address.vb code

Public Class address Public Property Name As String Public Property Phone As String Public Property EMail As String Public Property Comments As String

Public Class Address Private personName As String Private personEmail As String Private personPhone As String Private personComments As String Public Property Name As String Set(ByVal value As String) personName = value End Set Get Return personName End Get End Property Public Property EMail As String Set(ByVal value As String) personEmail = value End Set Get Return personEmail End Get End Property Public Property Phone As String Set(ByVal value As String) personPhone = value End Set Get Return personPhone End Get End Property Public Property Comments As String Set(ByVal value As String) personComments = value End Set Get Return personComments End Get End Property End Class End Class

Email Address Book - Microsoft Visual Studio ? f Quick Launch (Ctrl+Q) File Edit View Project Build Debug Team Tools Test R Tools Analyze Window Help Mom Puckett MP GDebugAny CPU Email Address Book AddNew.vb [Design] ? Email Address Book AddNew.vb formAddressBook.vb* + X Click address.vb | Solution Explorer

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!