Question: I have this Visual basic program. It has some errors. COuld you please help me. I place Error note infront of error areas. Could you
I have this Visual basic program. It has some errors. COuld you please help me. I place Error note infront of error areas. Could you please help me.
Here are the codes.
Customer Information Form Codes:
Public Class CustomerForm
'New Line Start
'Form level member
Dim Customers As String 'I did this
Private Sub Customers() As New Arraylist ' ERROR
Private Sub CustomerForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'New line start
CreateCustomer("Darrel", "Hilton", "dhilton@somecompany.com")
CreateCustomer("Fran", "Peoples", "fpeoples@thisorg.org")
CreateCustomer("Bill", "Scott", "bscott@ourtown.gov")
'New Line end
End Sub
'new line start
Public ReadOnly Property SelectedCustomer() As Customer
Get
If Customers.SelectedIndex <> -1 Then ' error
'Return this customer
Return CType(Customers(FirstCustomers.SelectedIndex), Customer) 'Error
End If
End Get
End Property
'end added line
Private Sub AddNewCustomer_Click(sender As Object, e As EventArgs) Handles AddNewCustomer.Click
'new line start
Dim strFirstName = FirstName.Text
Dim strLastName = FirstName.Text
Dim strEmail = FirstName.Text
Dim strCreateCustomer(strFirstName, strLastName, strEmail)
'new line ends
End Sub
'new line start
Public Sub CreateCustomer(firstName As String, lastName As String, email As String)
'Declare a customer object
Dim objNewCustomer As Customer
'Create the new customer
objNewCustomer.FirstName = firstName
objNewCustomer.LastName = lastName
objNewCustomer.Email = email
'Add the new customer to the list
objCustomers.Add(objNewCustomer) 'Error
'Add the new customer to the ListBox control
objCustomers.Items.Add(objNewCustomer) 'Error
'new line ends'''Error
End Sub
Private Sub SelectHighlightedCustome_Click(sender As Object, e As EventArgs) Handles SelectHighlightedCustome.Click
'start new line
'If no customer is selected, then error and exit
' If FirstCustomers.SelectedIndex = -1 Then 'Error
'Display error message and exit
MessageBox.Show("ERROR...no customer selected.")
Exit Sub
'End If
'Get customer info and display it in the order form
Dim objCustomerSelected As Customer = SelectedCustomer
DroneDogs.FirstName.Text = objCustomerSelected.FirstName
DroneDogs.LastName.Text = objCustomerSelected.LastName
DroneDogs.Email.Text = objCustomerSelected.Email
'end line
End Sub
End Class
DroneDogOrder_Codes:
Public Class DroneDogs
Private Sub SalesTax1_Click(sender As Object, e As EventArgs) Handles TotalCost1.Click
End Sub
Private Sub CalculateOrder_Click(sender As Object, e As EventArgs) Handles CalculateOrder.Click
'New Lines Start
'Variables declaration
Dim intNumBeef, intNumPork, intNumTurkey, intTotDogs As Integer 'Declare variables as Integer
Dim db1Subtotal, db1SalesTaxAmt, db1TotalCost As Double ''Declare variables as Decimal
Const DBL_COST_PER_DOG As Double = 1.99 'Declare variables and constant
Const DBL_SALES_TAX_RATE As Double = 0.07 'Declare variables and constant
'Converting Variables
intNumBeef = Convert.ToInt32(BeefDogs.Text) 'Extract text from the text boxes and convert them to numeric variables
intNumPork = Convert.ToInt32(PorkDogs.Text) 'Extract text from the text boxes and convert them to numeric variables
intNumTurkey = Convert.ToInt32(TurkeyDogs.Text) 'Extract text from the text boxes and convert them to numeric variables
'Calculation
intTotDogs = intNumBeef + intNumPork + intNumTurkey ' Calculating total no of Dogs
db1Subtotal = intTotDogs * DBL_COST_PER_DOG ' Calculating Sub Total
db1SalesTaxAmt = db1Subtotal * DBL_SALES_TAX_RATE ' Calculating Sales Tax
db1TotalCost = db1Subtotal + db1SalesTaxAmt ' Calculating Total Cost
'Converting to two decimals
SubTotal.Text = db1Subtotal.ToString("c2") ' Converting Sub Total to two Decmals in SubTotal text box
SalesTax.Text = db1SalesTaxAmt.ToString("c2") ' Converting Sales Tax to two Decmals in SalesTax text box
TotalCost.Text = db1TotalCost.ToString("c2") ' Converting Total Cost to two decimals in TotalCost text box
'New Lines End
End Sub
Private Sub TeotalCost_TextChanged(sender As Object, e As EventArgs) Handles TotalCost.TextChanged
End Sub
Private Sub PorkDogs1_TextChanged(sender As Object, e As EventArgs) Handles PorkDogs.TextChanged
End Sub
Private Sub Exit1_Click(sender As Object, e As EventArgs) Handles Exit1.Click
Me.Close() 'This will end the running of the program
End Sub
Private Sub TurkeyDogs1_TextChanged(sender As Object, e As EventArgs) Handles TurkeyDogs.TextChanged
End Sub
Private Sub TurkeyDogs_Click(sender As Object, e As EventArgs) Handles TurkeyDogs1.Click
End Sub
Private Sub SubmitOrder_Click(sender As Object, e As EventArgs) Handles SubmitOrder.Click
'New Line Start
If Permission.Checked = False Then
MessageBox.Show("ERROR...You must check the location permission check box.")
ElseIf TotalCost.Text = "" Then
MessageBox.Show("ERROR...You must order at least one item.")
ElseIf Email.Text = "" Then
MessageBox.Show("ERROR...Please get customer information for this order.")
Else
MessageBox.Show("Thank you for ordering from DroneDogs!")
End If
'New Line End
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub GetCustomerInfo_Click(sender As Object, e As EventArgs) Handles GetCustomerInfo.Click
'new line start
CustomerForm.Show()
'new line ends
End Sub
Private Sub ClearForm_Click(sender As Object, e As EventArgs) Handles ClearForm.Click
'Start New Lines
BeefDogs.Text = ""
PorkDogs.Text = ""
TurkeyDogs.Text = ""
SubTotal.Text = ""
SalesTax.Text = ""
TotalCost.Text = ""
FirstName.Text = ""
LastName.Text = ""
Email.Text = ""
'End New Lines
End Sub
Private Sub DroneDogs_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
Customer Codes:
Public Structure Customer 'Deleted and added
'Public members
Public FirstName As String
Public LastName As String
Public Email As String
'Formats the display
Public Overrides Function ToString() As String
Return FirstName & " " & LastName & " (" & Email & ")"
End Function
End Structure ' New lines end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
