Question: Using Murach visual basic programming Exercise 4-1 Modify the Invoice Total application Open the Invoice Total application 1. Open the application in the C:VB 2015Chapter

Using Murach visual basic programming Exercise 4-1 Modify the Invoice Total application Open the Invoice Total application

1. Open the application in the C:\VB 2015\Chapter 04\InvoiceTotal directory. This application is almost the same as the one thats presented in figure 4-20, but it uses permissive type semantics and implicit narrowing casts.

2. Test the application with a valid subtotal to verify that the correct discount is being taken. Then, enter a valid subtotal like 225.50 that will yield a discount amount that has more than two decimal places, and make sure that only two decimal places are displayed for the discount amount and total. Use strict type semantics

3. Stop the test run, and change the type semantics for the project to strict as shown in figure 4-8. Then, review the errors that are now underlined in the code for the Invoice Total form. Note also that a light bulb is displayed when you point to either of these errors, which means that you can use a Quick Actions menu to fix them.

4. If necessary, refer back to figure 3-15 to see how Quick Actions menus work. Then, use the suggestion in the menu for the first error to fix it. This will add a CDec function to your code. Now, display the Quick Actions menu for the second error to see its suggestion, but dont take it. Instead, just add a D after the literal to show the compiler that this is a Decimal value. Now, compile and test to see that this code works.

5. Enter $$1000 for the subtotal and click the Calculate button. This time, an exception should occur, Visual Studio should enter break mode, and the Exception Assistant should display a message that indicates that the input string was not in a correct format. This shows that exceptions still occur, even though youre using strict type semantics.

6. If you like using strict type semantics, turn this option on for all new applications by using the technique in figure 4-8. Experiment with the code

7. Modify the first statement in the btnCalculate_Click procedure so it uses the Parse method of the Decimal class instead of the CDec function. Then, test the application to verify that it still works the same.

8. Round the values that are stored in the discountAmount and invoiceTotal variables to two decimal places. Then, delete the FormatCurrency functions for these variables and note the errors that this causes. To fix these errors, use the ToString method, not the suggestion from the Quick Actions menu. Then, test the application to make sure that only two decimal places are displayed for the discount amount and total.

9. Save the solution and close it.

below is the code :

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 = 0.25D

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)

txtSubtotal.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

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!