greenxeyezz
10-26-2008, 07:32 AM
Okay, I do not do much VB coding, and I do not know if its cause of lack of sleep or what.
I for the life of me, cannot figure out the most simplist way around this problem.
I have a stupid little program. User inputs data. it calculates, and outputs. IF user wants to update the prices, or accessories, itll throw an error, because values are changed to outputs. Can anyone take a look and let me know what they think I am missing...
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'will test if there is an input in the text field and see if its blank and give error 1 or non numeric and give message 2
If txtBasePrice.Text = "" Then
MessageBox.Show("Need to Input A Correct Car Price", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtBasePrice.Text <> "" AndAlso Not IsNumeric(txtBasePrice.Text) Then
MessageBox.Show("Need to Input a Number for Car Price", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
'checks for each checkbox selected and adds price accordingly
With Me
If chkStereo.Checked = True Then
'Add Price
decAccessories = decSTEREOSYSTEM
End If
If chkLeather.Checked = True Then
'Add Price
decAccessories = decSTEREOSYSTEM + decLEATHER
End If
If chkNavi.Checked = True Then
'Add Price
decAccessories = decSTEREOSYSTEM + decLEATHER + decNAVI
End If
'checks for which radio button is selected and will add price accordingly
If radPearlized.Checked = True Then
decColor = decPEARLIZED
ElseIf radCustom.Checked = True Then
decColor = decCUSTOMDETAILING
Else
decColor = 0
End If
'no input or non numeric inputs results in 0 trade in
If txtTradeIn.Text = "" Or Not IsNumeric(txtTradeIn.Text) Then
decTradeIn = 0
Else
decTradeIn = Decimal.Parse(txtTradeIn.Text)
End If
'calculations and outputs
decBasePrice = Decimal.Parse(txtBasePrice.Text)
decSubtotal = decAccessories + decBasePrice + decColor
decTotal = decSubtotal + (decSubtotal * decSALESTAX)
decAmountDue = decTotal - decTradeIn
txtAccessoriesFinish.Text = (decAccessories + decColor).ToString("C2")
txtSubtotal.Text = decSubtotal.ToString("c2")
txtSalesTax.Text = (decSubtotal * decSALESTAX).ToString("C2")
txtTotal.Text = decTotal.ToString("C2")
txtAmountDue.Text = decAmountDue.ToString("C2")
txtTradeIn.Text = decTradeIn.ToString '("C2")
txtBasePrice.Text = decBasePrice.ToString '("C2")
End With
End If
End Sub
I for the life of me, cannot figure out the most simplist way around this problem.
I have a stupid little program. User inputs data. it calculates, and outputs. IF user wants to update the prices, or accessories, itll throw an error, because values are changed to outputs. Can anyone take a look and let me know what they think I am missing...
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'will test if there is an input in the text field and see if its blank and give error 1 or non numeric and give message 2
If txtBasePrice.Text = "" Then
MessageBox.Show("Need to Input A Correct Car Price", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtBasePrice.Text <> "" AndAlso Not IsNumeric(txtBasePrice.Text) Then
MessageBox.Show("Need to Input a Number for Car Price", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
'checks for each checkbox selected and adds price accordingly
With Me
If chkStereo.Checked = True Then
'Add Price
decAccessories = decSTEREOSYSTEM
End If
If chkLeather.Checked = True Then
'Add Price
decAccessories = decSTEREOSYSTEM + decLEATHER
End If
If chkNavi.Checked = True Then
'Add Price
decAccessories = decSTEREOSYSTEM + decLEATHER + decNAVI
End If
'checks for which radio button is selected and will add price accordingly
If radPearlized.Checked = True Then
decColor = decPEARLIZED
ElseIf radCustom.Checked = True Then
decColor = decCUSTOMDETAILING
Else
decColor = 0
End If
'no input or non numeric inputs results in 0 trade in
If txtTradeIn.Text = "" Or Not IsNumeric(txtTradeIn.Text) Then
decTradeIn = 0
Else
decTradeIn = Decimal.Parse(txtTradeIn.Text)
End If
'calculations and outputs
decBasePrice = Decimal.Parse(txtBasePrice.Text)
decSubtotal = decAccessories + decBasePrice + decColor
decTotal = decSubtotal + (decSubtotal * decSALESTAX)
decAmountDue = decTotal - decTradeIn
txtAccessoriesFinish.Text = (decAccessories + decColor).ToString("C2")
txtSubtotal.Text = decSubtotal.ToString("c2")
txtSalesTax.Text = (decSubtotal * decSALESTAX).ToString("C2")
txtTotal.Text = decTotal.ToString("C2")
txtAmountDue.Text = decAmountDue.ToString("C2")
txtTradeIn.Text = decTradeIn.ToString '("C2")
txtBasePrice.Text = decBasePrice.ToString '("C2")
End With
End If
End Sub