'------------------------------------------------------------------------------------------- ' BOOKMANAGER CLASS 'This module contains the capability to compute sales totals, sales tax, and amount due for 'each transaction. It also maintains a running total of daily sales figures (actual # of books sold 'and total amt of $$ collected, and total sales tax collected. 'The class has three properties: Price, Quantity, & Taxrate ' '------------------------------------------------------------------------------------------- Public Class BookManager Private bookPrice As Decimal 'property for the price of the book Private myquantity As Integer 'property for quantity of books purchased Private storeTaxRate As Decimal 'the tax rate is passed from btnCalculate_click Private totalTax As Decimal 'hold the actual formatted value of the tax #Region "Properties" '---here we manage the price they will send/get from our class ' ***Properties are PUBLIC by default so you can leave off "Public" when declaring them*** ''' ''' Sets or gets the Price of the book as a decimal ''' Property Price() As Decimal Get Return bookPrice End Get Set(ByVal value As Decimal) bookPrice = value End Set End Property '---here we manage the quantity they will send/get from our class ''' ''' Sets or gets the quantity of the books sold as an integer. ''' Property Quantity() As Integer Get Return myquantity End Get Set(ByVal Value As Integer) If Value >= 0 Then myquantity = Value End If End Set End Property ''' ''' Sets or gets the store tax rate as a decimal ''' Property TaxRate() As Decimal Get Return storeTaxRate End Get Set(ByVal Value As Decimal) storeTaxRate = Value End Set End Property #End Region #Region "Methods" ''' ''' This method computes the amount of sales tax as a decimal. ''' Public Function ComputeTax() As Decimal '---calculate the sales tax based on the numbers they pass to us Dim Tax As Decimal Tax = FormatNumber(quantity * bookPrice * taxRate, 2) totalTax = Tax 'save this so I can use it again in the ComputeTotalSale Function Return Tax 'send this back to the calling procedure(btnCalculate_click) End Function ''' ''' This method computes the total sale using the price, quantity, and salestax properties and returns a decimal. ''' Public Function ComputeTotalSale() As Decimal '---now compute the total sale Dim Total As Decimal Total = FormatNumber((bookPrice * Quantity) + totalTax, 2) Return Total '---you can also do it like this if you want: 'Return (bookPrice * quantity) + totalTax End Function ''' ''' This method computes the sub total of the sale using the price and quantity properties and returns a decimal. ''' Public Function ComputeSubTotal() As Decimal Dim SubTotal As Decimal SubTotal = FormatNumber(Quantity * bookPrice, 2) Return SubTotal End Function #End Region End Class ***************Here I use the class to manage running totals in the store Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click If txtQuantity.Text = "" Or txtPrice.Text = "" Then MsgBox("Please complete the form....", MsgBoxStyle.Exclamation, "Book Store Message") Exit Sub End If '---they are ready to check out '---assign stuff from text boxes to MybookStore so it can do its thing Try '---pass my class the stuff in the text box MyBookStore.Price = txtPrice.Text MyBookStore.Quantity = txtQuantity.Text MyBookStore.TaxRate = SALESTAXRATE '---compute this purchase txtTax.Text = MyBookStore.ComputeTax.ToString txtsubTotal.Text = MyBookStore.ComputeSubTotal.ToString txtTotalDue.Text = MyBookStore.ComputeTotalSale.ToString '---update daily totals dailyNumSales += CInt(txtQuantity.Text) dailySales += CDec(txtTotalDue.Text) dailySalesTax += CDec(txtTax.Text) '---now put totals in the labels lblGrandNumSales.Text = dailyNumSales.ToString lblGrandTotalSales.Text = FormatNumber(dailySales.ToString, 2) lblGrandTotalTax.Text = FormatNumber(dailySalesTax.ToString, 2) Catch MsgBox("An error occured while completing this transaction." & Err.Description, MsgBoxStyle.Critical, "Broken Book Transaction") PrepareMyForm() End Try End Sub