Hello again! I'm almost finished this project. However, the Clear button stopped doing its thing. It keeps giving me an "Invalid Cast Exception" whenever I am pressing the clear button. The project includes 2 forms--- JobInformation and Summary.
The code follows:
'Program Name: JobInformation
'Programmer: Zabinga
'Date: 11/28/2011
'Description: This program produces a summary of the amounts due for a bill for Pat's Auto Repair Shop.
' It incorporates menus, job information, a splash form, a summary form, and an About box form.
'Form: JobInformation
Option Strict On
Public Class JobInformation
'Declare projectwide variables.
Public Shared JobNumberString As String
Public Shared CustomerNameString As String
Public Shared PartsDecimal As Decimal
Public Shared HoursOfLaborDecimal As Decimal
'Declare module-level variables.
Public Shared SubTotalDecimal As Decimal
Public Shared SalesTaxRateDecimal As Decimal
Public Shared TotalDecimal As Decimal
Public Shared LaborInteger As Integer
'Declare constants.
Const SALES_TAX_RATE_Decimal As Decimal = 0.08D
Const LABOR_COST_Decimal As Decimal = 50D
'Private Sub CustomerNameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerNameTextBox.TextChanged
'CustomerNameString = CustomerNameTextBox.Text
'End Sub
Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
' Calculate and display the current amounts and add to totals.
' Declare on the DIM level.
' Declare a WithEvents variable.
Dim PartsDecimal As Decimal
Dim SubTotalDecimal As Decimal
Dim SalesTaxRateDecimal As Decimal
Dim TotalDecimal As Decimal
Dim HoursOfLaborDecimal As Decimal
'Dim CustomerNameString As String
'Calculate the extended price and add to job total.
Try
PartsDecimal = Decimal.Parse(PartsTextBox.Text)
HoursOfLaborDecimal = Decimal.Parse(HoursOfLaborTextBox.Text)
SubTotalDecimal = PartsDecimal + LABOR_COST_Decimal * HoursOfLaborDecimal
TotalDecimal = SubTotalDecimal + (SALES_TAX_RATE_Decimal * SubTotalDecimal)
If PartsDecimal > 0 Then
'Call a function procedure.
SalesTaxRateDecimal = FindTax(SubTotalDecimal)
ElseIf HoursOfLaborDecimal > 0 Then
HoursOfLaborDecimal = LABOR_COST_Decimal * HoursOfLaborDecimal
Else
SalesTaxRateDecimal = 0
End If
TotalDecimal = SubTotalDecimal + (SALES_TAX_RATE_Decimal * SubTotalDecimal)
HoursOfLaborTextBox.Text = HoursOfLaborDecimal.ToString("N")
PartsTextBox.Text = PartsDecimal.ToString("C")
SubTotalTextBox.Text = SubTotalDecimal.ToString("N")
SalesTaxRateTextBox.Text = SALES_TAX_RATE_Decimal.ToString("N")
TotalTextBox.Text = TotalDecimal.ToString("C")
CustomerNameTextBox.Text = CustomerNameString.ToString()
'Allow clear for new job only.
ClearButton.Enabled = True
Catch PartsException As FormatException
MessageBox.Show("Quantity must be numeric.", "Data entry error",
MessageBoxButtons.OK, MessageBoxIcon.Information)
With PartsTextBox
.Focus()
.SelectAll()
End With
End Try
End Sub
Private Function FindTax(ByVal PartsDecimal As Decimal) As Decimal
'Calculate the sales tax.
Return (PartsDecimal * SALES_TAX_RATE_Decimal) + PartsDecimal
End Function
Private Sub JobNumberTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles JobNumberTextBox.TextChanged
JobNumberString = JobNumberTextBox.Text
End Sub
Private Sub CustomerNameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerNameTextBox.TextChanged
CustomerNameString = CustomerNameTextBox.Text
End Sub
Private Sub PartsTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PartsTextBox.TextChanged
PartsDecimal = CDec(PartsTextBox.Text)
End Sub
Private Sub HoursOfLaborTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HoursOfLaborTextBox.TextChanged
HoursOfLaborDecimal = CDec(HoursOfLaborTextBox.Text)
End Sub
Private Sub SubTotalTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SubTotalTextBox.TextChanged
SubTotalDecimal = CDec(SubTotalTextBox.Text)
End Sub
Private Sub SalesTaxRateTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalesTaxRateTextBox.TextChanged
SalesTaxRateDecimal = CDec(SalesTaxRateTextBox.Text)
End Sub
Private Sub TotalTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TotalTextBox.TextChanged
TotalDecimal = CDec(TotalTextBox.Text)
End Sub
Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
'Clear the appropriate textboxes.
JobNumberTextBox.Clear()
CustomerNameTextBox.Clear()
PartsTextBox.Clear()
HoursOfLaborTextBox.Clear()
SubTotalTextBox.Clear()
SalesTaxRateTextBox.Clear()
TotalTextBox.Clear()
With JobNumberTextBox
.Clear()
.Focus()
.SelectAll()
End With
PartsDecimal = 0
HoursOfLaborDecimal = 0
SubTotalDecimal = 0
SalesTaxDecimal = 0
TotalDecimal = 0
End Sub
Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OKButton.Click
Me.Close()
End Sub
End Class