I'm having trouble trying to get this button to work
correctly:
This is part of my homework and I don't know if I screwed it
up or something..
This is the "Next Item Button" which is supposed to
validate the quantity, weight and price. Each must be present
and numeric. For any bad data, display a message box.
Calculate the charge for the current item and add the charge
and weight into the appropriate totals. Do not calculate
shipping and handling on the individual items, but rather,
calculate the shipping and handling in the entire order.
Here is what I have done so far:
Dim mdecDue As Decimal
Dim mdecTotal As Decimal
Dim mdecWeightTotal As Decimal
Dim mdecWeight As Decimal
Dim mdecGrandTotal As Decimal
Const mdecShip As Decimal = 0.25D
Const mdecHandleLight As Decimal = 1D
Const mdecHandleMed As Decimal = 3D
Const mdecHandleHeavy As Decimal = 5D
Const mdecTAX_RATE As Decimal = 0.08D
Private Sub btnNext_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnNext.Click
Dim intQuantity As Integer
Dim decPrice As Decimal
Dim decWeight As Decimal
Dim decTotal As Decimal
Dim decTaxTotal As Decimal
Dim strMessage As String
If txtQuantity.Text <> "" Then
If IsNumeric(txtQuantity.Text) Then
'Good Data, let's perform calculations
Try
intQuantity = CInt(txtQuantity.Text)
decTotal = decPrice * intQuantity
decWeight = CInt(txtWeight.Text)
If decWeight < 10 Then
mdecWeightTotal = decTotal +
mdecHandleLight + (mdecShip * decWeight)
ElseIf decWeight >= 10 And decWeight
<= 100 Then
mdecWeightTotal = decTotal *
mdecHandleMed + (mdecShip * decWeight)
ElseIf decWeight > 100 Then
mdecWeightTotal = decTotal *
mdecHandleHeavy + (mdecShip * decWeight)
End If
mdecWeight += decWeight
lblDue.Text = FormatCurrency(mdecTotal)
lblShip.Text =
FormatCurrency(mdecWeightTotal)
Catch
strMessage = "Calculation Error"
MessageBox.Show(strMessage,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Else
'Nonnumeric Data
strMessage = "Nonnumeric data."
MessageBox.Show(strMessage, "Data Entry
error", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtQuantity.Focus()
End If
Else 'Missing data
strMessage = "Enter the quantity."
MessageBox.Show(strMessage, "Data Entry
error", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub