Finishing up a mandatory class for graduation and have been working on my final for 2 days!!! I have to create a form that calculates the amount due for an order .....I am VB challenged and need some assistance to get this to work. Every time I run the program the total due will not display in the summary screen..... Any help would be greatly and I mean greatly appreciated!!!!!
Public Class MainForm
Const HANDLING_0_TO_10_Decimal As Decimal = 1D
Const HANDLING_10_TO_100_Decimal As Decimal = 3D
Const HANDLING_100_PLUS_Decimal As Decimal = 5D
Const TAX_RATE_Decimal As Decimal = 0.08D 'Rate for CA sales
Const SHIPPING_CHARGE_Decimal As Decimal = 0.25D 'Per pound charge
Friend amountDueTotalDecimal, weightTotalDecimal, _
taxDecimal, totalDueDecimal, shippingHandlingDecimal As Decimal
Private Function ShippingHandling(ByVal weightTotalDecimal As Decimal) As Decimal
'Calculate shipping and handling
Dim handlingDecimal, shippingDecimal As Decimal
Select Case weightTotalDecimal
Case 1 To 9
handlingDecimal = HANDLING_0_TO_10_Decimal
Case 10 To 100
handlingDecimal = HANDLING_10_TO_100_Decimal
Case Is > 100
handlingDecimal = HANDLING_100_PLUS_Decimal
End Select
shippingDecimal = weightTotalDecimal * SHIPPING_CHARGE_Decimal
Return shippingDecimal + handlingDecimal
End Function
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
'Exit from the form.
Me.Close()
End Sub
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
'Show the About form
Dim About As New AboutForm
About.Show()
End Sub
Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
'Clear all entries and reset all counters and accumulators for this customer.
With Me
.StreetTextBox.Clear()
.CityTextBox.Clear()
.StateTextBox.Clear()
.ZipTextBox.Clear()
.DescriptionTextBox.Clear()
.QuantityTextBox.Clear()
.WeightTextBox.Clear()
.PriceTextBox.Clear()
'Enable the customer information text boxes.
.NameTextBox.Enabled = True
.StreetTextBox.Enabled = True
.CityTextBox.Enabled = True
.StateTextBox.Enabled = True
.ZipTextBox.Enabled = True
.DescriptionTextBox.Enabled = True
.QuantityTextBox.Enabled = True
.WeightTextBox.Enabled = True
.PriceTextBox.Enabled = True
amountDueTotalDecimal = 0
weightTotalDecimal = 0
taxDecimal = 0
totalDueDecimal = 0
shippingHandlingDecimal = 0
With .NameTextBox
.Clear()
.Focus()
End With
End With
End Sub
Private Sub AddThisItemToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddThisItemToolStripMenuItem.Click
'Process the current item and add to the appropriate total
Dim QuantityInteger As Decimal
Dim weightDecimal, priceDecimal, itemAmountDecimal As Decimal
Dim messageString As String
With Me
'Verify that all data is valid
Try
Catch ex As Exception
End Try
QuantityInteger = Decimal.Parse(QuantityTextBox.Text)
Try
weightDecimal = Decimal.Parse(.WeightTextBox.Text)
Try
priceDecimal = Decimal.Parse(.PriceTextBox.Text)
'Perform calculations
weightDecimal *= QuantityInteger
itemAmountDecimal = QuantityInteger * priceDecimal
amountDueTotalDecimal += itemAmountDecimal
weightTotalDecimal += weightDecimal
.DescriptionTextBox.Clear()
.QuantityTextBox.Clear()
.WeightTextBox.Clear()
.PriceTextBox.Clear()
.DescriptionTextBox.Focus()
'Disable the customer information until the user chooses to clear the data.
.NameTextBox.Enabled = False
.StreetTextBox.Enabled = False
.CityTextBox.Enabled = False
.StateTextBox.Enabled = False
.ZipTextBox.Enabled = False
Catch priceException As FormatException
messageString = "Please input a valid number for the price."
MessageBox.Show(messageString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
With .PriceTextBox
.Focus()
.SelectAll()
End With
End Try
Catch weightException As FormatException
messageString = "Please input a valid number for the weight."
MessageBox.Show(messageString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
With .WeightTextBox
.Focus()
.SelectAll()
End With
End Try
End With
End Sub
Private Sub UpdateSummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateSummaryToolStripMenuItem.Click
'Display the summary form
With Me
'Calculate shipping
shippingHandlingDecimal = ShippingHandling(weightTotalDecimal)
'Calculate sales tax
If .StateTextBox.Text.ToUpper = "CA" Then
taxDecimal = amountDueTotalDecimal * TAX_RATE_Decimal
End If
'Calculate total due
totalDueDecimal = amountDueTotalDecimal + taxDecimal + shippingHandlingDecimal
'Disable the order information. Additional items would cause the shipping charges to be incorrect.
.DescriptionTextBox.Enabled = False
.QuantityTextBox.Enabled = False
.WeightTextBox.Enabled = False
.PriceTextBox.Enabled = False
End With
SummaryForm.ShowDialog()
End Sub
End Class