Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 6-1 Enhance the Invoice Total application In this exercise, you'll enhance the Invoice Total application of chapter 5 by adding a procedure that determines

Exercise 6-1 Enhance the Invoice Total application

In this exercise, you'll enhance the Invoice Total application of chapter 5 by adding a procedure that determines the discount percent to it. You'll also add another event handler to the application.

1. open the application that's in the C:\VB 2012\Chapter 06\ InvoiceTotal directory.

2. Start a Sub procedure with three parameters (customer type, subtotal, and discount percent) that will set the discount percent based on the customer type and subtotal. Then, copy the code for doing that from the event handler of the btnCalculate_Click procedure to the new Sub procedure, and modify this code so it works correctly.

3. Modify the code in the btnCalculate_Click procedure so it calls the Sub procedure to get the discount percent. As you enter the call, notice how the IntelliSense feature helps you enter the arguments. Then, test these changes to make sure they work.

4. Add a function procedure with two parameters (customer type and subtotal) that returns the discount percent. Then, modify the calling statement and any other code in the btnCalculate_Click procedure so it uses the Function procedure to get the discount percent. Now, test this change.

5. Add one event handler named ClearAllBoxes that handles the TextChanged event for both the Customer the Customer Type and Subtotal text boxes. This event handler should clear the values in the text boxes that display the results. After you test this change, close this project.

Public Class frmInvoiceTotal

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim subtotal As Decimal = CDec(txtSubtotal.Text) Dim discountPercent As Decimal

If txtCustomerType.Text = "R" Then If subtotal < 100 Then discountPercent = 0 ElseIf subtotal >= 100 AndAlso subtotal < 250 Then discountPercent = 0.1D ElseIf subtotal >= 250 Then discountPercent = 0.25D End If ElseIf txtCustomerType.Text = "C" Then If subtotal < 250 Then discountPercent = 0.2D Else discountPercent = 0.3D End If Else discountPercent = 0.4D End If

Dim discountAmount As Decimal = subtotal * discountPercent Dim invoiceTotal As Decimal = subtotal - discountAmount

txtDiscountPercent.Text = FormatPercent(discountPercent, 1) txtDiscountAmount.Text = FormatCurrency(discountAmount) txtTotal.Text = FormatCurrency(invoiceTotal)

txtCustomerType.Select() End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub

End Class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions