Member Avatar for djc1977

working on a project that calculates an amount due for an order. My problem i am facing is in regard to my clear button. The clear button will clear the fields for the current order and let you place another order that will allow the summary button to add up the totals of the orders and add sales tax, shipping and handling and total amount due. This is what I have for my clear button but for some reason, it's not adding my totals....any insight on what I am doing wrong?

Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click

Dim returnDialogResult As DialogResult
Dim messageString As String

With Me
'confirm clear of current order.
messageString = "Clear the current order figures?"
returnDialogResult = MessageBox.Show(messageString, "Clear Order", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)

If returnDialogResult = DialogResult.Yes Then 'User said yes.
'Clear the screen fields.
.descriptionTextBox.Clear()
.quantityTextBox.Clear()
.weightTextBox.Clear()
.priceTextBox.Clear()
.dollaramtTextBox.Clear()

Try
'add to Totals
'add only if not a new order/customer

If sumdollaramtDecimal > 0 Then
sumdollaramtDecimal += dollaramtDecimal
'Reset totals for next customer
dollaramtDecimal = 0
End If
Catch
messageString = "Error in calculations"
MessageBox.Show(messageString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End With
End Sub

1. sumdollaramtDecimal has to be more than 0 for any sum to be added to it. This looks like a logic error. Should that be If dollaramtDecimal > 0 Then sumdollaramtDecimal += dollaramtDecimal?
2. You need a process to transfer the text from the text box to the numbers you are using to track the order. That isn't shown. Are you sure that dollaramtDecimal has the calculations loaded before you cleared the boxes? Something like

if IsNumeric(quantityTextBox.Text) and IsNumeric(dollaramtTextBox.Text) Then
Dim i int32
i = quantityTextBox.Text
dollaramtDecimal = dollaramtTextBox.Text
dollaramtDecimal *= i
End If

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.