Public Class frmInvoiceTotal
Dim numberOfInvoices As Integer
Dim totalOfInvoices As Decimal
Dim invoiceAverage As Decimal
Dim largestInvoice As Decimal
Dim smallestInvoice As Decimal
Dim midPoint As Decimal
Dim newMin As Decimal
Dim newMax As Decimal
Dim currentMax As Decimal = 0
Dim currentMin As Decimal = 9999999
Private Sub btnCalculate_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim subtotal As Decimal = CDec(txtSubtotal.Text)
Dim discountPercent As Decimal = 0.25D
Dim discountAmount As Decimal = Math.Round(subtotal * discountPercent, 2)
Dim invoiceTotal As Decimal = subtotal - discountAmount
txtSubtotal.Text = FormatCurrency(subtotal)
txtDiscountPercent.Text = FormatPercent(discountPercent, 1)
txtDiscountAmount.Text = FormatCurrency(discountAmount)
txtTotal.Text = FormatCurrency(invoiceTotal)
numberOfInvoices += 1
totalOfInvoices += invoiceTotal
invoiceAverage = totalOfInvoices / numberOfInvoices
txtNumberOfInvoices.Text = numberOfInvoices.ToString
txtTotalOfInvoices.Text = FormatCurrency(totalOfInvoices)
txtInvoiceAverage.Text = FormatCurrency(invoiceAverage)
newMin = Math.Min(currentMin, subtotal)
txtSmallestInvoice.Text = FormatCurrency(newMin)
currentMin = newMin
newMax = Math.Max(currentMax, subtotal)
txtLargestInvoice.Text = FormatCurrency(newMax)
currentMax = newMax
txtSubtotal.Select()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub frmInvoiceTotal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnClearTotals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearTotals.Click
numberOfInvoices = 0
totalOfInvoices = 0
invoiceAverage = 0
newMin = 0
newMax = 0
txtNumberOfInvoices.Text = ""
txtTotalOfInvoices.Text = ""
txtInvoiceAverage.Text = ""
txtLargestInvoice.Text = ""
txtSmallestInvoice.Text = ""
txtMidPoint.Text = ""
End Sub
Private Sub txtLargestInvoice_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLargestInvoice.TextChanged
End Sub
End Class
This program takes invoices and discounts each one and gives the final price for each invoice. Then keeps track of how many invoices were entered as well as the average and total of each of the invoices. This is what I have so far and everything works fine except for the clear totals button which I can't get to reset the values I have to display the largest and smallest invoices. I can get them to clear out but not reset.
I need to add one more button to determine the midpoint between the largest invoice and the smallest invoice. I can't figure out the logic for this button. I have already been programming in java for about a year so I know about arrays and other data structures that I could potentially use here, but for this class in VB, we haven't gotten there yet and our professor does not want us to use any types of advanced data structures or loops.
Any help would be appreciated..I'm not asking for help with the actual code...just the logic behind it for right now.
Thanks,
Nick

New Topic/Question
Reply



MultiQuote




|