| | |
problems with variable accumulation
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 1
Reputation:
Solved Threads: 0
Hi, Im looking for any kind of nudge in the right direction. In this vb.net program I have declared 3 private variables, quantity, weight, and price. I will then type the following into textboxes and when I click the "add this item" button the info will be displayed into 3 matching labels. I coded so it will accumulate each order until done. Then there is an update summary button, this button shows the dollar amount due(price * quantity), sales tax, shipping and handling and then total amount due. Im almost done with this but I am having a problem with accumulating dollar amount due and shipping and handling. So far it will only calculate dollar amount due and shipping for one order only. When I type in multiple orders it will only give dollar amount due, etc, for the first one. I need to a know a way I could get the orders to accumulate in a variable but I just can 't figure out anything that works. Below I have copied some of the code for the addthisitem button and the update summary button.
Any help would be greatly appreciated.
Private Sub additemButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles additemButton.Click
Dim descriptionString As String
With Me
quantityDecimal = Decimal.Parse(.quantityTextBox.Text)
weightDecimal = Decimal.Parse(.weightTextBox.Text)
priceDecimal = Decimal.Parse(.priceTextBox.Text)
descriptionString = .productTextBox.Text
'Display and accumulate variables accordingly
.descriptionresultLabel.Text += vbNewLine & descriptionString.ToString
.quantityresultLabel.Text += vbNewLine & quantityDecimal.ToString
.weightresultLabel.Text += vbNewLine & weightDecimal.ToString
.priceresultLabel.Text += vbNewLine & priceDecimal.ToString
End With
End Sub
Private Sub updatesummaryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updatesummaryButton.Click
'Declare variables
Dim amountdueDecimal, handlingDecimal As Decimal
Dim shippingDecimal As Decimal
Dim salestaxDecimal, totalshippingDecimal As Decimal
Dim isConverted As Boolean
Dim isConverted2, isConverted3 As Boolean
With Me
isConverted = Decimal.TryParse(.quantityTextBox.Text, quantityDecimal)
If isConverted Then
isConverted2 = Decimal.TryParse(.priceTextBox.Text, priceDecimal)
'find a place for the below variables
If isConverted2 Then
amountdueDecimal += priceDecimal * quantityDecimal
salestaxDecimal = priceDecimal * quantityDecimal * 0.08D
Else : MessageBox.Show("Please enter non-zero values.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
With .priceTextBox
.Focus()
'Declaring boolean variable for shipping and handling calculations(last left off here)
isConverted3 = Decimal.TryParse(weightTextBox.Text, weightDecimal)
weightDecimal = weightDecimal * quantityDecimal
If isConverted3 Then
If weightDecimal < 10D Then
handlingDecimal = 1D
ElseIf weightDecimal >= 10D And weightDecimal <= 100 Then
handlingDecimal = 3D
ElseIf weightDecimal > 100D Then
handlingDecimal = 5D
End If
'display results
End If
End With
End If
'Display the shipping and handling total
shippingDecimal = weightDecimal * 0.25D
totalshippingDecimal = shippingDecimal + handlingDecimal
.resultLabel.Text = "Dollar Amount Due " & amountdueDecimal.ToString _
& vbNewLine & "Sales Tax " & salestaxDecimal.ToString & vbNewLine & _
"Shipping and Handling " & totalshippingDecimal.ToString
Else
MessageBox.Show("Please enter non-zero values.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
With .quantityTextBox
End With
.Focus()
End If
End With
Any help would be greatly appreciated.
Private Sub additemButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles additemButton.Click
Dim descriptionString As String
With Me
quantityDecimal = Decimal.Parse(.quantityTextBox.Text)
weightDecimal = Decimal.Parse(.weightTextBox.Text)
priceDecimal = Decimal.Parse(.priceTextBox.Text)
descriptionString = .productTextBox.Text
'Display and accumulate variables accordingly
.descriptionresultLabel.Text += vbNewLine & descriptionString.ToString
.quantityresultLabel.Text += vbNewLine & quantityDecimal.ToString
.weightresultLabel.Text += vbNewLine & weightDecimal.ToString
.priceresultLabel.Text += vbNewLine & priceDecimal.ToString
End With
End Sub
Private Sub updatesummaryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updatesummaryButton.Click
'Declare variables
Dim amountdueDecimal, handlingDecimal As Decimal
Dim shippingDecimal As Decimal
Dim salestaxDecimal, totalshippingDecimal As Decimal
Dim isConverted As Boolean
Dim isConverted2, isConverted3 As Boolean
With Me
isConverted = Decimal.TryParse(.quantityTextBox.Text, quantityDecimal)
If isConverted Then
isConverted2 = Decimal.TryParse(.priceTextBox.Text, priceDecimal)
'find a place for the below variables
If isConverted2 Then
amountdueDecimal += priceDecimal * quantityDecimal
salestaxDecimal = priceDecimal * quantityDecimal * 0.08D
Else : MessageBox.Show("Please enter non-zero values.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
With .priceTextBox
.Focus()
'Declaring boolean variable for shipping and handling calculations(last left off here)
isConverted3 = Decimal.TryParse(weightTextBox.Text, weightDecimal)
weightDecimal = weightDecimal * quantityDecimal
If isConverted3 Then
If weightDecimal < 10D Then
handlingDecimal = 1D
ElseIf weightDecimal >= 10D And weightDecimal <= 100 Then
handlingDecimal = 3D
ElseIf weightDecimal > 100D Then
handlingDecimal = 5D
End If
'display results
End If
End With
End If
'Display the shipping and handling total
shippingDecimal = weightDecimal * 0.25D
totalshippingDecimal = shippingDecimal + handlingDecimal
.resultLabel.Text = "Dollar Amount Due " & amountdueDecimal.ToString _
& vbNewLine & "Sales Tax " & salestaxDecimal.ToString & vbNewLine & _
"Shipping and Handling " & totalshippingDecimal.ToString
Else
MessageBox.Show("Please enter non-zero values.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
With .quantityTextBox
End With
.Focus()
End If
End With
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Pdf 2 Sql
- Next Thread: Displaying Totals based on DB fields
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account arithmetic array basic bing browser button buttons center check code crystalreport cuesent data database datagrid datagridview date datetimepicker dissertation dissertations dissertationtopic dropdownlist eclipse excel fade file-dialog filter ftp generatetags google gridview hardcopy images input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters pdf picturebox picturebox1 port position print printing problem project read remove save searchbox searchvb.net select serial settings shutdown soap survey table tcp temperature text textbox timer timespan toolbox transparency trim update user vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year





