I have been working on this program for days and I can not figure out what I am doing wrong. I have most of the code done but I am getting error messages with the radio buttons. The new user radio button is supposed to take the data inserted in the textboxes and display it in the second listbox but it only does this with the first input. How can I fix this? The existing user radio button is supposed to allow me to select a line from the second listbox and then it should split the line and add the data to the three textboxes. I throws an exception error when I click the existing user radio button. How can I correct this error? This is the code I have so far. I am going to post the entire code just in case it is needed.
Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
'I am dimming my variables that I need
Dim name As String
Dim address As String
Dim city As String
Dim firstlast As String
Dim invoicenumber As String
Dim chairs As Double
Dim sofas As Double
'I am assigning value to my variables
name = txtName.Text
address = txtAddress.Text
city = txtCity.Text
chairs = CDbl(txtChairs.Text) * 350
sofas = CDbl(txtSofas.Text) * 925
'I am using if clauses to make sure the user puts values into the text boxes and if not then a message box will appear
If name = "" Then
MessageBox.Show("Please Enter Your Name.")
txtName.Focus()
End If
If address = "" Then
MessageBox.Show("Please Enter Your Address.")
txtAddress.Focus()
End If
If city = "" Then
MessageBox.Show("Please Enter Your City, State, and Zip in Correct Format.")
txtCity.Focus()
End If
If address.Contains(",") = False Then
MessageBox.Show("Please Enter In Correct Format: City, St., Zip.")
End If
'These are my functions that I made for the invoice number and name reverse
invoicenumber = GenerateinvoiceNumber(txtName.Text)
firstlast = RevName(name)
'I am adding all of the items to my listbox
lstResults.Items.Clear()
lstResults.Items.Add("INVOICE NUMBER: " & " " & invoicenumber.ToUpper)
lstResults.Items.Add(String.Empty)
lstResults.Items.Add("Name: " & " " & RevName(txtName.Text.ToUpper))
lstResults.Items.Add("Address: " & "" & address.ToUpper)
lstResults.Items.Add("City: " & " " & city.ToUpper)
lstResults.Items.Add(String.Empty)
lstResults.Items.Add("Number of Chairs: " & "" & txtChairs.Text)
lstResults.Items.Add("Number of Sofas: " & " " & txtSofas.Text)
lstResults.Items.Add(String.Empty)
lstResults.Items.Add("Cost: " & " " & FormatCurrency(chairs + sofas))
lstResults.Items.Add("Sales Tax:" & " " & FormatCurrency((chairs + sofas) * 0.05))
lstResults.Items.Add("--------------------------------------------")
lstResults.Items.Add("Total Cost: " & " " & FormatCurrency((chairs + sofas) * 1.05))
End Sub
'This is the function for the name reverse.
Function RevName(ByVal name As String) As String
Dim firstlast() As String
'This split is to take the part of the word after the comma
firstlast = Split(txtName.Text.ToUpper, ", ")
'This if clause is to make sure that the name is formatted correctly with a comma
If name.Contains(", ") = False Then
MessageBox.Show("Please Enter Your Name In Correct Format.")
End If
'This will show the function and the correct formatting in my list box
Return firstlast(1) & " " & firstlast(0)
End Function
'This is my function to create the invoice number
Function GenerateinvoiceNumber(ByVal s As String) As String
'Dimming the variables I need for my function
Dim initials() As String
Dim firstInitial, invoicenumber, city As String
'Assigning values to the variables
'I am using a split to get the letters from the last name
initials = s.Split(CChar(","))
'I am taking the letters that I need using a substring
firstInitial = initials(0).Trim.Substring(0, 2).ToUpper
city = txtCity.Text
'This is to get the value of the textbox city and the length of the input
Dim length = city.Length
'This is to get the first two letters of the name behind the comma and the city substring will extract the last four characters in the city textbox
invoicenumber = (firstInitial & city.Substring(length - 4, 4))
'This is to return the value of the function
Return invoicenumber
End Function
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'This is to clear the form and start over
txtName.Clear()
txtAddress.Clear()
txtCity.Clear()
txtChairs.Clear()
txtSofas.Clear()
lstResults.Items.Clear()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'This is to end the entire form
Me.Close()
End Sub
This is the Part I am having trouble with
*** Private Sub rbtnNew_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnNew.CheckedChanged
If rbtnNew.Checked Then rbtnNew.Enabled = True Else rbtnExisting.Enabled = False
If rbtnNew.Checked = True Then
lstCustomer.Items.Add(RevName(txtName.Text.ToUpper) & " , " & (txtAddress.Text.ToUpper) & " , " & (txtCity.Text.ToUpper))
End If
End Sub
Private Sub rbtnExisting_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnExisting.CheckedChanged
Dim output() As String
Dim listselected As String
Dim name1, address2, city2 As String
listselected = CStr(lstCustomer.SelectedItem)
'I am using a split to get the letters from the last name
output = listselected.Split(CChar(","))
'Assigning values to the variables
name1 = txtName.Text
address2 = txtAddress.Text
city2 = txtCity.Text
'I am taking the letters that I need using a substring
txtName.Text = output(0).Trim.Substring(CInt(","))
txtAddress.Text = output(1).Trim.Substring(CInt(","))
txtCity.Text = output(2).Trim.Substring(CInt(","))
If rbtnExisting.Checked Then rbtnExisting.Enabled = True Else rbtnNew.Enabled = False
lstResults.Items.Clear()
txtChairs.Clear()
txtSofas.Clear()
End Sub***
End Class