bigboywasim
Member
- Joined
- Sep 29, 2006
- Messages
- 18
- Programming Experience
- Beginner
I am suppose to use byref and byval but my calculations are not coming our right. Please help me guys it is due today.
VB.NET:
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'DECLARATION SECTION
'**********************************************************************************************************************************************
' -- Declares Variables at the local level.
' -- Declares Constants at the local level.
'**********************************************************************************************************************************************
Dim decSalesPrice As Decimal
Dim decAccessoriesAndFinishTotal As Decimal
Dim decSalesTax As Decimal
Dim decSubtotal As Decimal
Dim decTradeInAllowance As Decimal
Dim decAmountDue As Decimal
Dim blnErrorFlag As Boolean = False
'CAll SECTION
'**********************************************************************************************************************************************
' -- Calls Neccessary Items
'**********************************************************************************************************************************************
Call ValidateData(decSalesPrice, decTradeInAllowance, blnErrorFlag)
If blnErrorFlag = True Then
Exit Sub
End If
Call AccessoriesAndFinishTotal(decAccessoriesAndFinishTotal)
Call PerformAllCalculations(decSalesTax, decSalesPrice, decSubtotal, decAmountDue, decTradeInAllowance, decAccessoriesAndFinishTotal)
Call DispalyAllResults(decSalesTax, decSalesPrice, decSubtotal, decAmountDue, decTradeInAllowance, decAccessoriesAndFinishTotal)
End Sub
#End Region
#Region "VALIDATE DATA"
' CATCHES CALCULATION AND FAILURE OF CONVERSION FUNCTION ERRORS
' DISPALYS APPROPRIATE ERROR MESSAGE IN MESSAGE BOX
' CHANGES COLOR OF APPROPRIATE TEXTBOX RED IF ERROR OCCURED
'***************************************************************************************************************************************************
' -- Catches Calculation and Failure of Conversion Function Errors
' -- Dispalys Appropriate Error Message in Message Box
' -- Changes Color of Appropriate Textbox Red If Error Occurred
'***************************************************************************************************************************************************
Private Sub ValidateData(ByRef decSalesPrice As Decimal, ByRef decTradeInAllowance As Decimal, ByRef blnRrrorFalg As Boolean)
Dim blnErrorFlag As Boolean = False
Try
If CDec(txtCarSalesPrice.Text) > 100000 Then
MsgBox("Car Sales Price Exceeds 100000. Enter Smaller Number", MsgBoxStyle.Critical)
txtCarSalesPrice.BackColor = Color.Red
blnErrorFlag = True
End If
decSalesPrice = CDec(txtCarSalesPrice.Text)
Catch UserError1 As InvalidCastException
MsgBox("Enter Only Numbers for Car Sales Price and Don't Leave Blank", MsgBoxStyle.Critical)
txtCarSalesPrice.BackColor = Color.Red
Catch UserError2 As ArithmeticException
MsgBox("Overflow Please Enter Smaller Value for Car sales Price", MsgBoxStyle.Critical)
txtCarSalesPrice.BackColor = Color.Red
End Try
Try
If CDec(txtTradeInAllowance.Text) > 50000 Then
MsgBox("Trade In Allowence Exceeds 50000. Enter Smaller Number", MsgBoxStyle.Critical)
txtTradeInAllowance.BackColor = Color.Red
blnErrorFlag = True
End If
decTradeInAllowance = CDec(txtTradeInAllowance.Text)
Catch UserError1 As InvalidCastException
MsgBox("Enter Only Numbers for Trade In Allowance and Don't Leave Blank", MsgBoxStyle.Critical)
txtTradeInAllowance.BackColor = Color.Red
Catch UserError2 As ArithmeticException
MsgBox("Overflow Please Enter Smaller Value for Trade In Allowance", MsgBoxStyle.Critical)
txtTradeInAllowance.BackColor = Color.Red
End Try
End Sub
#End Region
#Region "FINISH & ACCESSORIES CHARGES "
' CALCULATES ACCESSORIES AND FINISH
'***************************************************************************************************************************************************
' -- Calculates Accessories and Finish
'***************************************************************************************************************************************************
Private Sub AccessoriesAndFinishTotal(ByRef decAccessoriesAndFinishTotal As Decimal)
'Test the option buttons for added charges
If radPearlized.Checked = True Then
decAccessoriesAndFinishTotal += mdecPEARIZED_FINISH_PRICE
ElseIf radCustomizedDetailing.Checked = True Then
decAccessoriesAndFinishTotal += mdecCUSTOMIZED_DETAILING
End If
'Test the check boxes for added charges
If chkStereoSystem.Checked = True Then
decAccessoriesAndFinishTotal += mdecSTEREO_SYSTEM_PRICE
End If
If chkLeatherInterior.Checked = True Then
decAccessoriesAndFinishTotal += mdecLEATHER_INTERIOR_PRICE
End If
If chkComputerNavigation.Checked = True Then
decAccessoriesAndFinishTotal += mdecCOMPUTER_NAVIGATION_PRICE
End If
End Sub
#End Region
#Region "PERFORM ALL CALCULATIONS"
'CALCULATES SALES TAX
'CALCULATES SUBTOTAL
'CALCULATES AMOUNT DUE
'***************************************************************************************************************************************************
' -- Calcualtes Sales Tax
' -- Calcultes Subtotal
' -- Calcualtes Amount Due
'***************************************************************************************************************************************************
Private Sub PerformAllCalculations(ByRef decSalesTax As Decimal, ByRef decSubtotal As Decimal, ByRef decAmountDue As Decimal, ByVal decSalesPrice As Decimal, ByVal decAccessoriesAndFinishTotal As Decimal, ByVal decTradeInAllowance As Decimal)
decSalesTax = (decSalesPrice + decAccessoriesAndFinishTotal) * mdecTax_Rate
decSubtotal = (decSalesTax + decSalesPrice) + (decAccessoriesAndFinishTotal)
decAmountDue = (decSubtotal - decTradeInAllowance)
End Sub
#End Region
#Region "DISPALY ALL RESULTS"
'DISPAYS ACCESSORIES AND FINISH
'DISPAYS SALES TAX
'DISPAYS SUBTOTAL
'DISPAYS AMOUNT DUE
'DISPAYS FORMATTED SALES PRICE
'DISPAYS FORMATTED TRADE IN ALLOWANCE
'***************************************************************************************************************************************************
' -- Dispalys Accessories and Finish
' -- Dispalys sales tax
' -- Dispalys subtotal
' -- Dispalys Amount Due
' -- Dispalys Formatted Sales Price
' -- Dispalys Formatted Trade In Allowance
'***************************************************************************************************************************************************
Private Sub DispalyAllResults(ByVal decAccessoriesAndFinishTotal As Decimal, ByVal decSalesTax As Decimal, ByVal decSubtotal As Decimal, ByVal decAmountDue As Decimal, ByVal decSalesPrice As Decimal, ByVal decTradeInAllowance As Decimal)
lblAccessoriesAndFinish.Text = FormatCurrency(decAccessoriesAndFinishTotal)
lblSalesTax.Text = FormatCurrency(decSalesTax)
lblSubtotal.Text = FormatCurrency(decSubtotal)
lblAmountDue.Text = FormatCurrency(decAmountDue)
txtCarSalesPrice.Text = FormatCurrency(decSalesPrice)
txtTradeInAllowance.Text = FormatCurrency(decTradeInAllowance)
End Sub
#End Region