Question

The Murach's Visual Basic 2015 Book And Visual Studio Exercise 7-2 Enhance the Invoice Total application...

The Murach's Visual Basic 2015 Book And Visual Studio

Exercise 7-2 Enhance the Invoice Total application

If you did exercise 6-1 in the last chapter, this exercise asks you to add data validation and exception handling to it.

1. Copy the Invoice Total application from your C:\VB 2015\Chapter 06 directory to your Chapter 07 directory. This should be your solution to exercise 6-1 of the last chapter.

2. If your application has both a Sub procedure and a Function procedure for setting the discount percent, delete the Sub procedure.

3. Go to the Sub procedure for setting the discount percent and comment out the Else clause. That means that a discount percent is only set for customer type codes of R and C, so assume that these are the only valid customer type codes.

4. Add data validation for the customer type entry so it has to be either R or C. To do that, write a Function procedure named IsValidCustomerType that validates the entry, displays an error message if the entry is invalid, and returns a Boolean value that indicates whether the type is valid.

5. Call the IsValidCustomerType function at the start of the btnCalculate_Click procedure, and exit from the procedure if the customer type is invalid. Then, test this change.

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

Me.GetDiscountPercent(txtCustomerType.Text, subtotal, discountPercent)
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 GetDiscountPercent(customerType As String, subtotal As Decimal,
ByRef discountPercent As Decimal)
If customerType = "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 customerType = "C" Then
If subtotal < 250 Then
discountPercent = 0.2D
Else
discountPercent = 0.3D
End If
Else
discountPercent = 0.4D
End If
End Sub

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

Private Sub ClearResultBoxes(sender As Object,
e As EventArgs) _
Handles txtCustomerType.TextChanged, txtSubtotal.TextChanged
txtDiscountPercent.Text = ""
txtDiscountAmount.Text = ""
txtTotal.Text = ""
End Sub
End Class

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Public Class Form1

Private Sub btnCalculate_Click(sender As Object,
e As EventArgs) Handles btnCalculate.Click

Dim subtotal As Decimal = CDec(txtSubtotal.Text)
Dim discountPercent As Decimal

Me.GetDiscountPercent(txtCustomerType.Text, subtotal, discountPercent)
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 GetDiscountPercent(customerType As String, subtotal As Decimal, ByRef discountPercent As Decimal)
If customerType = "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 customerType = "C" Then
If subtotal < 250 Then
discountPercent = 0.2D
Else
discountPercent = 0.3D
End If
Else
discountPercent = 0.4D
End If
End Sub

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

Private Sub ClearResultBoxes(sender As Object, e As EventArgs) Handles txtSubtotal.TextChanged
txtDiscountPercent.Text = ""
txtDiscountAmount.Text = ""
txtTotal.Text = ""
End Sub
Private Function IsValidCustomerType() _
As Boolean
If IsValidCustomerType = "R" Then
MessageBox.Show("Customer Type has to be R or C or T", "Entry Error")
txtCustomerType.Select()
Return False
Else
Return True
End If
If Not IsValidCustomerType = "C" Then
MessageBox.Show("Customer Type has to be R or C or T", "Entry Error")
txtCustomerType.Select()
Return False
Else
Return True
End If

End Function
End Class

if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)

Add a comment
Know the answer?
Add Answer to:
The Murach's Visual Basic 2015 Book And Visual Studio Exercise 7-2 Enhance the Invoice Total application...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Murach's C# 2015 Training & Reference: I need help with both Exercise 4-1. I figured out...

    Murach's C# 2015 Training & Reference: I need help with both Exercise 4-1. I figured out steps 1-4, but not understanding how to modify the code for 5 & 6. Code is: private void btnCalculate_Click(object sender, EventArgs e)        {            decimal subtotal = Convert.ToDecimal(txtSubtotal.Text);            decimal discountPercent = .25m;            decimal discountAmount = subtotal * discountPercent;            decimal invoiceTotal = subtotal - discountAmount;            txtDiscountPercent.Text = discountPercent.ToString("p1");   ...

  • so im trying to make a grade program and idk what im doing wrong actually if...

    so im trying to make a grade program and idk what im doing wrong actually if someone can help? (heres the lines of code i have so far if its wrong let me know how to fix them Option Strict On Option Explicit On Public Class Form1 Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim lblscore1 As Double Dim lblscore2 As Double Dim lblscore3 As Double lblscore1 = CDbl(Txtscore1.Text) lblscore2 = CDbl(Txtscore2.Text) lblscore3 = CDbl(Txtscore3.Text) lblaverage =...

  • I need help with this problem in Visual Basic 2012: Write a program that allows the...

    I need help with this problem in Visual Basic 2012: Write a program that allows the user to specify two numbers and then adds, subtracts, multiplies, or divides them when the user clicks on the appropriate button. The output should give the type of arithmetic performed and the result. Whenever one of the numbers in an input text box is changed, the output text box should be cleared. Also, if the number 0 is entered into the second text box,...

  • Project 2 – Memory Match Game Purpose This Windows Classic Desktop application plays a simple matching game. The game si...

    Project 2 – Memory Match Game Purpose This Windows Classic Desktop application plays a simple matching game. The game simulates a card game where the cards a placed face down and the player flips over pairs of cards in an attempt to find matching cards.   Program Procedure Display a 4x4 grid of “face down” cards. Assign the letters A through H randomly to the cards in pairs. Allow the user to click on a card to “flip” it over and...

  • I really need some help fixing a code error in Visual Basic I was wondering if...

    I really need some help fixing a code error in Visual Basic I was wondering if anyone could help fix the error that I'm about to provide in bold thanks so much! I'll also tell what the error is. Public Class MainForm Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click Me.Close() End Sub Dim img As Image = Image.FromFile("C:\Users\Pranesh\Pictures\11599264.jpg") house1PictureBox.Image = img house2PictureBox.Image = img house3PictureBox.Image = img house4PictureBox.Image = img house1PictureBox.Visible = False house2PictureBox.Visible = False house3PictureBox.Visible...

  • Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb...

    Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb Public Class frmNewItem Public InvItem As InvItem Private Sub frmNewItem_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.LoadComboBox() End Sub Private Sub LoadComboBox() cboSizeOrManufacturer.Items.Clear() If rdoPlant.Checked Then cboSizeOrManufacturer.Items.Add("1 gallon") cboSizeOrManufacturer.Items.Add("5 gallon") cboSizeOrManufacturer.Items.Add("15 gallon") cboSizeOrManufacturer.Items.Add("24-inch box") cboSizeOrManufacturer.Items.Add("36-inch box") Else cboSizeOrManufacturer.Items.Add("Bayer") cboSizeOrManufacturer.Items.Add("Jobe's") cboSizeOrManufacturer.Items.Add("Ortho") cboSizeOrManufacturer.Items.Add("Roundup") cboSizeOrManufacturer.Items.Add("Scotts") End If End Sub Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click If IsValidData() Then InvItem = New InvItem(CInt(txtItemNo.Text),...

  • Visual Basic: Create an application that simulates a tic tac toe game. The form uses 9...

    Visual Basic: Create an application that simulates a tic tac toe game. The form uses 9 large labels to display the x's and o's. The application should use a two dimensional integer array to simulate the game board in memory. When the user clicks the "New Game" button the application should step throguh the array storing a random number of 0 to 1 in each element. The numer 0 represent the letter o and the number 1 reprsents the letter...

  • Program using visual basic.net You will create a very simple two numbers calculator with save options;...

    Program using visual basic.net You will create a very simple two numbers calculator with save options; here is the specifications for the application. Create a form divided vertically in two halves with right and left panels 1- In the left panel you will create the following control, the label or the value of the control will be in "" and the type of the control will in [] a- "First Number" [textbox] b- "Second number" [texbox] c- "Result" [textbox] -...

  • Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the valu...

    Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the value the user enters based on the selected conversion type. The application should handle the following conversions: From To Conversion Miles - Kilometers: 1 mile = 1.6093 kilometers Kilometers - Miles: 1 kilometer = 0.6214 miles Feet - Meters: 1 foot = 0.3048 meters Meters - Feet: 1 meter = 3.2808 feet Inches - Centimeters: 1 inch = 2.54 centimeters Centimeters - Inches: 1...

  • 6-1 Test and debug the Invoice Application i need help with this please.. all help is...

    6-1 Test and debug the Invoice Application i need help with this please.. all help is appreciated Source code Java: import java.util.Scanner; import java.text.NumberFormat; public class InvoiceApp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String choice = "y"; while (!choice.equalsIgnoreCase("n")) { // get the input from the user System.out.print("Enter customer type (r/c): "); String customerType = sc.next(); System.out.print("Enter subtotal: "); double subtotal = sc.nextDouble(); // get the discount percent double discountPercent = 0.0; switch(customerType) {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT