' Project: Simple Calculation ' Programmer: Andy McCone ' Date: Oct 5th 2007 'Description: This project multiplies Price * Quantity ' Returns the Subtotal, Tax and Total Public Class mainForm Dim m_runningTotalDecimal As Decimal Dim m_numberOfSalesInteger As Integer Const m_TAX_RATE_decimal As Decimal = 0.089D Private Sub calculateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles calculateButton.Click Dim priceDecimal As Decimal Dim quantityInteger As Integer Dim subtotalDecimal As Decimal Dim taxDecimal, totalDecimal As Decimal Try If IsNumeric(priceTextbox.Text) Then If IsNumeric(quantityTextbox.Text) Then If nameTextBox.Text <> "" Then 'Capture numbers from textboxes and put into variables quantityInteger = CInt(quantityTextbox.Text) priceDecimal = CDec(priceTextbox.Text) 'Calculate price*quantity, the tax and the total subtotalDecimal = priceDecimal * quantityInteger taxDecimal = subtotalDecimal * m_TAX_RATE_decimal totalDecimal = subtotalDecimal + taxDecimal 'Add to Running Total and Number of sales m_runningTotalDecimal += totalDecimal m_numberOfSalesInteger += 1 'Display results in labels subtotalLabel.Text = FormatCurrency(subtotalDecimal) taxLabel.Text = FormatCurrency(taxDecimal) totalLabel.Text = FormatCurrency(totalDecimal) Else MessageBox.Show("Please fill out your Name", "Erorr") End If Else MessageBox.Show("Use number only for the quantity", "Erorr") End If Else MessageBox.Show("Use numbers only for the price", "Error") End If Catch ex As Exception MessageBox.Show("Internal program error, we are very sorry.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Warning) priceTextbox.Text = "" End Try End Sub Private Sub summaryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles summaryButton.Click 'Display Running Total and Number of sales runningTotalLabel.Text = FormatCurrency(m_runningTotalDecimal) numOfSalesLabel.Text = FormatNumber(m_numberOfSalesInteger) End Sub End Class