Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with visual basics. I have several text boxes and labels Quantity, p

ID: 3601161 • Letter: I

Question

I need help with visual basics. I have several text boxes and labels Quantity, price, subtotal, sales tax, shipping and the total. The total will not add together when I hit next item, However, my subtotal keeps a running total, But I also need it to keep adding up the total.

'this line calculates the subtotal before taxes and shipping

sngSubTotal = sngQuantity * msngQuiltCost
'this line calculates the sales tax based on the tax rate constant
sngSalesTax = sngSubTotal * CSngSalesTax

'this line caluclates the total for the order
sngTotal = sngSubTotal + sngSalesTax + sngShipping

I want the final total output of the quantity of items ordered  

Quantity Quilt Price Color Sub Total Sales Tax Shipping Total Sub Total Sales Tax Shipping Order Total Next ltem Number Of Sales Today Clear Clear All Exit Todays GrandTotal

Explanation / Answer

Public Class Form1 'Modular Variable Declaration Section Dim mintOrdersPlacedToday As Integer Dim msngTotalOfOrdersToday As Single Dim msngShippingCost As Single = -1 Const csngSalesTaxRate As Single = 0.0625 Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click 'Local Variable Declaration Section Dim sngShirtPrice As Single = 10 Dim sngPremiumShirtPrice As Single = 20 Dim sngHatsPrice As Single = 15 Dim sngStickersPrice As Single = 5 Dim sngSubTotal As Single Dim sngSalesTax As Single Dim sngOrderTotal As Single Dim intQuantity As Integer 'Data Input Section If msngShippingCost = -1 Then MessageBox.Show("Please choose a shipping method", "Error", MessageBoxButtons.OK) 'Displays an error messsage when no shipping method is chosen Exit Sub 'Terminates the click event to allow shipping method to be chosen first End If Try 'Checks to see if the price is a valid number. 'If it is, then it is assigned to the quantity variable, if not, error message and the event is halted. intQuantity = txtShirts.Text Catch ex As Exception MessageBox.Show("Please enter a valid number of Shirts.", "Error", MessageBoxButtons.OK) 'Displays an error messsage when there is an invalid number txtShirts.Text = "" 'Clears the text box txtShirts.Focus() 'Puts the cursor in the price textbox Exit Sub 'Terminates the click event to allow valid input. End Try Try Catch ex As Exception End Try 'Calculation Section sngSubTotal = intQuantity * sngShirtPrice 'Calculates the subtotal sngSalesTax = sngSubTotal * csngSalesTaxRate 'Calculates Sales Tax based on the sales tax rate constant sngOrderTotal = sngSubTotal + sngSalesTax + msngShippingCost 'Calculates total for the sale mintOrdersPlacedToday = mintOrdersPlacedToday + 1 'Calculates the number of orders placed today, adds one to the previous number msngTotalOfOrdersToday = msngTotalOfOrdersToday + sngOrderTotal 'Calculates the Total of all the orders placed today 'Output section lblShowSubTotal.Text = FormatCurrency(sngSubTotal) 'Displays the Subtotal lblShowSalesTax.Text = FormatCurrency(sngSalesTax) 'Displays the Sales Tax lblShowOrderTotal.Text = FormatCurrency(sngOrderTotal) 'Displays the Order Total lblShowOrdersPlacedToday.Text = mintOrdersPlacedToday 'Displays the Orders placed today lblShowTotalOfOrders.Text = FormatCurrency(msngTotalOfOrdersToday) 'Displays the Total of the Orders placed today lblShowShippingCost.Text = FormatCurrency(msngShippingCost) 'Displays the total of the shipping cost End Sub Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Dim result = MessageBox.Show(" Are you sure you want to exit?", "Are you sure?", MessageBoxButtons.YesNo) 'Shows a messagebox for the user asking if they want to exit the program and gives them options. If result = DialogResult.Yes Then 'States that if the user clicks Yes, the program will close Me.Close() 'Exits the program End If End Sub Private Sub btnClearCurentSale_Click(sender As Object, e As EventArgs) Handles btnClearCurentSale.Click 'Clears the information from current sale and resets the form for the next sale radPickup.Checked = True 'Checks the Pickup radio button radPickup.Checked = False 'Unchecks the Pickup radio button btnCalculate.Enabled = True 'Enables the Calculate button msngShippingCost = -1 'Sets Shipping Cost to -1 lblShowShippingCost.Text = "" 'Clears the Shipping Cost label lblShowOrderTotal.Text = "" 'Clears the Order Total label lblShowSalesTax.Text = "" 'Clears the Sales Tax label lblShowSubTotal.Text = "" 'Clears the Sub Total label txtShirts.Text = "" 'Clears the Shirts text box txtShirts.Focus() 'Puts the cursor in the Shirts text box End Sub Private Sub radPickup_CheckedChanged(sender As Object, e As EventArgs) Handles radPickup.CheckedChanged msngShippingCost = 0 'Sets shipping cost as $0 lblShowShippingCost.Text = "Free" 'Sets Shipping Cost label to show $0 lblShowOrderTotal.Text = "" 'Clears the Order Total label End Sub Private Sub radGround_CheckedChanged(sender As Object, e As EventArgs) Handles radGround.CheckedChanged msngShippingCost = 6.75 'Sets shipping cost as $6.75 lblShowShippingCost.Text = FormatCurrency(6.75, 2) 'Sets Shipping Cost label to show $6.75 lblShowOrderTotal.Text = "" 'Clears the Order Total label End Sub Private Sub radTwoDay_CheckedChanged(sender As Object, e As EventArgs) Handles radTwoDay.CheckedChanged msngShippingCost = 12 'Sets shipping cost as $12 lblShowShippingCost.Text = FormatCurrency(12, 2) 'Sets Shipping Cost label to show $12 lblShowOrderTotal.Text = "" 'Clears the Order Total label End Sub Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click 'Clears the information for everything on the form txtShirts.Text = "" 'Clears the Shirts text box txtShirts.Focus() 'Puts the cursor in the Shirts text box lblShowSubTotal.Text = "" 'Clears the Sub Total label lblShowSalesTax.Text = "" 'Clears the Sales Tax label lblShowShippingCost.Text = "" 'Clears the Shipping Cost label lblShowOrderTotal.Text = "" 'CLears the Order Total label lblShowOrdersPlacedToday.Text = "" 'Clears the Orders Placed Today label lblShowTotalOfOrders.Text = "" 'Clears the Total of Orders Today label mintOrdersPlacedToday = 0 'Resets the counter msngTotalOfOrdersToday = 0 'Resets the accumulator End Sub End Class