' Project: Variables and Constants ' Programmer: Andy McCone ' Date: Jan 18th 2008 'Description: This program takes the price and quantity of a ' sales to give us the subtotal, tax and total ' using local and module variables, as well as constants Public Class mainForm 'Module level Variables and Constants Dim m_numOfSalesCounterInteger As Integer Dim m_totalSalesDecimal As Decimal Const m_TAX_RATE_decimal As Decimal = 0.085D Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click Try 'Declare Variables Dim quantityInteger As Integer Dim priceDecimal As Decimal Dim subTotalDecimal As Decimal Dim taxDecimal, totalDecimal As Decimal 'Capture values in textboxes quantityInteger = Integer.Parse(quantityTextBox.Text) priceDecimal = Decimal.Parse(priceTextBox.Text) 'Calculate the subtotal and tax subTotalDecimal = quantityInteger * priceDecimal taxDecimal = subTotalDecimal * m_TAX_RATE_decimal 'Calculate Total totalDecimal = subTotalDecimal + taxDecimal 'Display results taxLabel.Text = taxDecimal.ToString("c") totalPriceLabel.Text = FormatCurrency(totalDecimal) 'Count the number of sales and display m_numOfSalesCounterInteger = m_numOfSalesCounterInteger + 1 'm_numOfSalesCounterInteger += 1 numOfSalesLabel.Text = FormatNumber(m_numOfSalesCounterInteger, 0) 'Update running total of sales and display m_totalSalesDecimal = m_totalSalesDecimal + totalDecimal totalSalesLabel.Text = FormatCurrency(m_totalSalesDecimal) Catch ex As Exception 'Error message for user MessageBox.Show("Please use only Numbers", "Errorr") End Try End Sub Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click 'Close program Me.Close() End Sub End Class