Current location: Hot Scripts Forums » Programming Languages » Visual Basic » calculation problem


calculation problem

Reply
  #1 (permalink)  
Old 04-15-10, 04:27 AM
shanehenery shanehenery is offline
New Member
 
Join Date: Apr 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
calculation problem

Hi

It is a calculating form IN VB coding to indicate on how many books you bay and the total discount you will get after you click calculate
it is not all the coding in the hole form
just the calculate part
It is not calculating the 15% discount in the
DiscountTextBox
, discount price

DiscountedTextBox
it only gives me a 0.00 amount

and the calculations in the summary group box
nothing is adding up

QuantitySumTextBox
DiscountSumTextBox
DiscountedAmountSumTextBox
AverageDiscountTextBox
is not calculating at all


Expand|Select|Wrap|Line Numbers Expand|Select|Wrap|Line Numbers Private Sub>
Code:
CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click 
 
'Calculate the price and discount 
Dim QuantityInteger As Integer 
Dim PriceDecimal, ExtendedPriceDecimal, DiscountDecimal, DiscountedPriceDecimal, AverageDiscountDecimal, _ 
DISCOUNT_RATE_Decimal, ExtendedPriceDecilmal, QuantitySumInteger, DiscountSumDecimal, SaleCountInteger, _ 
DiscountedSumDecimal, AverageDescountDecimal As Decimal 
 
Try 
'Convert quantity to numeric variable 
QuantityInteger = Integer.Parse(QuantityTextBox.Text) 
Catch ex As Exception 
End Try 
 
Try 
'Convertprice if quantity was successful. 
PriceDecimal = Decimal.Parse(PriceTextBox.Text) 
'Calculate values for sale. 
ExtendedPriceDecimal = QuantityInteger * PriceDecimal 
DiscountDecimal = Decimal.Round( _ 
(ExtendedPriceDecimal * DISCOUNT_RATE_Decimal), 1) 
DiscountedPriceDecimal = ExtendedPriceDecilmal - DiscountDecimal 
 
'Calculate summary values. 
QuantitySumInteger += QuantityInteger 
DiscountSumDecimal += DiscountDecimal 
SaleCountInteger += 1 
AverageDiscountDecimal = DiscountSumDecimal / SaleCountInteger 
 
'Format and display answer for the sale 
ExtendedPriceTextBox.Text = ExtendedPriceDecimal.ToString("C") 
DiscountTextBox.Text = DiscountDecimal.ToString("N") 
DiscountedTextBox.Text = DiscountedPriceDecimal.ToString("C") 
'Format and display summary values. 
QuantitySumTextBox.Text = QuantitySumInteger.ToString() 
DiscountTextBox.Text = DiscountedSumDecimal.ToString("C") 
AverageDiscountTextBox.Text = AverageDescountDecimal.ToString("C") 
 
Catch PriceException As FormatException 
'Handle a price exception 
MessageBox.Show("Price must be numeric.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) 
With PriceTextBox 
.Focus() 
.SelectAll() 
End With 
End Try 
Try 
Catch QuantityException As FormatException 
'Handle a quantity exception. 
MessageBox.Show("Quantity must be numeric. ", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) 
With QuantityTextBox 
.Focus() 
.SelectAll() 
End With 
End Try 
End Sub

Last edited by digioz; 04-16-10 at 09:13 AM. Reason: Please use code tags
Reply With Quote
  #2 (permalink)  
Old 04-18-10, 10:56 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
There is no value for DISCOUNT_RATE_Decimal.
Anything multiplied by 0 will equal 0.
Code:
DiscountDecimal = Decimal.Round( _ 
(ExtendedPriceDecimal * DISCOUNT_RATE_Decimal), 1)
Also, what's the "_" for in the equation?
__________________
Jerry Broughton

Last edited by job0107; 04-18-10 at 11:02 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
login, roles problem dbrook007 ASP.NET 10 11-10-06 03:42 PM
Form Display Problem neevrap02 Visual Basic 1 09-05-06 05:18 AM
Calculation Problem progress Perl 2 10-11-05 02:47 PM
Asp and Microsoft Access 2002 problem gop373 ASP 2 10-06-04 09:13 AM
Problem With Form Calculation franzi ASP 3 03-26-04 04:10 AM


All times are GMT -5. The time now is 01:18 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.