Hi
It is a calculating form 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
DiscountTextBox
, discount price
DiscountedTextBox
it only gifs me a 0.00 amount
ore any of the calculations in the summary group box
QuantitySumTextBox
DiscountSumTextBox
DiscountedAmountSumTextBox
AverageDiscountTextBox
is not calculating at all - Private Sub> 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
Thanks
24 2910 TIP: When you first created your question you were asked to wrap your code with [code] tags. It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
If you put a breakpoint at line 3 and walk through the code line by line, I'll bet it does run... then you get an error... then bail out of the function. Right?
Did you do what tlhintoq told you to do? I think you just reposted your code without trying...
Steven
Hi
I have put in a breakpoint in line 3
then when I debug the hole program doesn't work
I had to end the program
Hi
Once I debug it gives me a message
( A first chance exception of type 'System.FormatException' occurred in mscorlib.dll )
then I add my numbers to calculate
the red dot of the breakpoint gets that yellow arrow on it and the code turns yellow
after I click calculate then there is a message telling me
(not Responding)
then I need to end the program
I'm going to assume this is your very first program in Visual Studio.
Visual Studio is a powerful program. You really should take the time to learn how to use it and understand it. There are many good books on learning Visual Studio *before* you try to write code with it.
It's kind of like learning to use the controls of a car (gas, brake, steering) before asking for directions on how to drive from New York to Los Angeles.
the red dot of the breakpoint gets that yellow arrow on it and the code turns yellow
after I click calculate then there is a message telling me
(not Responding)
then I need to end the program
Your program is 'not responding' because it is stopped on the breakpoint line. While it is stopped you can look at the 'Autos' and 'Locals' pallets to see the values of your variables. You walk through your code one line at a time by pressing the F-10 function key. There are other options as well, listed in the Debug menu, such as F11 to step into a method you are calling.
Once I debug it gives me a message
( A first chance exception of type 'System.FormatException' occurred in mscorlib.dll )
Someplace where you are trying to format one of your numbers is failing.
You probably also want to start with a smaller amount of code and work up to something as large as what you are doing here. Start with just 1 calculation and 1 text box. Work out what is wrong with the formatting calls you are making. *THEN* you can apply the correct technique to a second calculation, then a third, and so on.
Hi
Yes this is my 3rd project
I have put in a breakpoint and went from line to line with F10
from this line - Const DISCOUNT_RATE_Decimal As Decimal = 0.15D
and it stops by this line - Private Sub RnR_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
once it stoped then my project pops up and it gives me a message in a Immediate window
[message] A first chance exception of type 'System.FormatException' occurred in mscorlib.dll [/message]
wat can be wrong and how do i fix it
can you pleas help
- Const DISCOUNT_RATE_Decimal As Decimal = 0.15D
I'm pretty sure you have to specify the 0.15 as a decimal with a lower case d not D
Hi
It is still not working
I cant change the - Const DISCOUNT_RATE_Decimal As Decimal = 0.15D
0.15D to a lower case d
It gos back to a D by defult
And I have declared - Const DISCOUNT_RATE_Decimal As Decimal = 0.15D
as a Decimal
Do you have to supply the 'D' at all?
Can't you just say
Const DISCOUNT_RATE_Decimal As Decimal = 0.15
I can do that in C#
Hi
Yes , I can remove the 'D' but it doesn't make to program to calculate
it is still not working
Am I not seeing something here???
I don't event see the CONST line that you indicated in your code or your RnR_Load sub code either.
Maybe I am missing something. This does not look like the code you are talking about.
Correct me if I am wrong.
cheers,
HI
This is the code I am using
It needs to calculate the amount of books you bye with its discount of 15%
nothing is calculating -
Public Class Form1
-
-
'Declare module-level variables and constants
-
Private QuantitySumInteger, SaleCountinteger As Integer
-
Private DiscountSumDecimal, DiscountedPriceSumDecimal As Decimal
-
Const DISCOUNT_RATE_Decimal As Decimal = 0.15D
-
-
Private Sub 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, 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), 2)
-
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")
-
DiscountedPriceTextBox.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
-
Your entire process is in a single Try/Catch block. That means if any single part fails, the entire things fails. You should break this up so that each individual calculation is in it's own try/catch.
[message] A first chance exception of type 'System.FormatException' occurred in mscorlib.dll [/message]
You know you have a format exception. So stop trying to integrate formating in your calls. - DiscountTextBox.Text = DiscountedSumDecimal.ToString("C")
Take out all your "C" and "N" formatters. Just throw whatever string is made into the textbox to at least see if your calculations are working. *AFTER IT ALL CALCULATING* then you can format just one line and run it again. If that works, format one more line.
I have put in a breakpoint and went from line to line with F10
from this line
Expand|Select|Wrap|Line Numbers
Const DISCOUNT_RATE_Decimal As Decimal = 0.15D
If you are only using F10 then you are skipping over the actual calculation part, for line-by-line stepping.
Since you want to debug the method that takes place after you click the [Calculate] button, that is where you should put the breakpoint: Inside the Calculate button handler. - Dim QuantityInteger As Integer
Line 11 from your sample above.
Now you can step through the method causing trouble until you find the bug.
Hi
I have added the individual Try/Catch block of each calculation
and I have removed the "C"and"N"
it is still not calculating at all
only thing it is calculating is the "QuantityTextBox"+ "PriceTextBox" ="ExtendedPriceTextBox"
I am a little confused again.
I now see where you are declaring DISCOUNT_RATE_Decimal (line 6) as a constant, but then later under your button code you dimension it again (line 13). I have never done that but usually when you dimension a variable it resets the value of the variable to the default value (which would be 0 in this case).
Could it be that by dimensioning your variable AFTER you have set it as a constant that it is no longer a constant and is proceeding through your code with a value of 0 instead of .15 ?
cheers,
Hi
ok I left DISCOUNT_RATE_Decimal as a Const
and deleted the one that was extra in dimensioning(line 13)
it is calculating the dscount as 0.15D thats fine now
but it is showing "0.00" in the DiscountTextBox
when I click calculate.
but the rest of the calculation is not working
be cos from ther I need to calculate the summary af the Total Discount , Total Discount Amount and Average Discount
Hi
and it is giving me this message "A first chance exception of type 'System.DivideByZeroException' occurred in mscorlib.dll" and "A first chance exception of type 'System.FormatException' occurred in mscorlib.dll"
where can I look for the code so then I can fix it
@shanehenery
OK you are still confusing me with your responses.
Fixing your dimensioning fixed your discount problem.
Now you say the DiscountTextBox displays 0.00 - does this mean DiscountedSumDecimal gives the proper answer but is not being displayed on your form properly?
What does it mean when you say the rest of the calculation is not working?
Maybe the other people are mind readers but I failed that course.
Can you please be very very specific and indicate what the variables are when the system gives the error.
Also as previously indicated remove ALL error trapping and ALL formatting and work with just the bare bones code needed to get the result you want. After that is working you can throw back in formatting and trapping.
cheers,
Here's what I'm hearing at this point...
"The entire thing doesn't work - some one tell me what's wrong with it." You need to debug your program one line at a time. You need to use the tools Visual Studio provides. The 'Locals' and 'Autos' pallets will show you the values of your variables at each line.
Do a calculation, step one line
Do a calculation, step one line
As soon as the answer to one calculation is wrong - stop debugging and fix that one calculation.
Then start over
Do a calculation, step one line
Do a calculation, step one line
Eventually you will fix each calculation so they all work.
This is how basic debugging works. One line at a time. It's slow and tedieous: Welcome to programming!
This is a very simple need. It is nothing more complex than 7th grade math. Don't make more of it than it really is. It's easy to get frustrated and see the entire program as one big problem. Don't get caught in that trap. Break it down into little pieces. One line at a time. Don't try to solve the entire application. Just solve one line. Then solve another line.
have you found the solution?
Hi
I have a problem in my coding I will like to deduct 15% from my RentalAmountTextBox to be displayed in my
AmountDueTextBox - AmountDueTextBox.Text = RentalAmountDecimal - 0.1
then in my AmountDueTextBox it only displays -0.1
it is not doing the calculation
an you pleas help -
Public Class VideoBonanza
-
'Declare module-level variables and constants.
-
-
Private TotalSumInteger, MemberInteger, SaleCountInteger As Integer
-
Private TotalRentalSumDecimal As Decimal
-
Const Discount_Rate_Decimal As Decimal = 0.1D
-
-
Private Sub VideoBonanza_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
-
End Sub
-
-
Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
-
'Calculate the rental amounts
-
-
Dim QuantityInteger As Integer
-
Dim RentalAmountDecimal, DiscountDecimal, AmountDueDecimal As Decimal
-
-
Try
-
'Convert Quantity to numeric variable.
-
QuantityInteger = Integer.Parse(QuantityTextBox.Text)
-
AmountDueTextBox.Text = (RentalAmountDecimal - DiscountDecimal).ToString("C")
-
DiscountDecimal = Decimal.Round(RentalAmountDecimal * Discount_Rate_Decimal, 2)
-
AmountDueDecimal = RentalAmountDecimal - DiscountDecimal
-
RentalAmountTextBox.Text = RentalAmountDecimal.ToString("C")
-
AmountDueTextBox.Text = AmountDueDecimal.ToString("C")
-
-
Catch Member As Exception
-
'Handle a member exception
-
MessageBox.Show("Enter Member Number.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
-
With MemberTextBox
-
.Focus()
-
.SelectAll()
-
End With
-
End Try
-
Try
-
'Calculate the summary
-
TotalSumInteger += MemberInteger
-
MemberInteger += 1
-
'Calculate the total Rentals of the quantity videos rented
-
TotalRentalSumDecimal += QuantityInteger.ToString()
-
DiscountTextBox.Text = RentalAmountDecimal - 0.1
-
AmountDueTextBox.Text = RentalAmountDecimal - 0.1
-
-
Catch ex As Exception
-
End Try
-
-
Try
-
'Calculate the rentals amount
-
RentalAmountTextBox.Text = (QuantityInteger * 1.8).ToString("C")
-
-
'Calculate the total Rentals of the quantity videos rented
-
TotalRentalSumTextBox.Text = TotalRentalSumDecimal
-
-
TotalSumTextBox.Text = MemberInteger.ToString()
-
-
Catch ex As Exception
-
-
End Try
-
-
End Sub
-
Shane:
I once asked you if this was your first project and you said it was your third.
Looking at your posts I see you started 3 threads. *ALL* of them are for the inability to calculate in a project, with only slight differences.
Please do not start multiple threads for the same issue. It divides efforts to help you.
It is becoming very clear that you need to start on a smaller scale. All three of your projects are failing for the same reason: You are trying to create programs that must go through an entire process of multiple calculations before you have worked out how to do a single calculation.
In addition, you need to take some time to learn your way around Visual Studio itself.
Microsoft Press does some good "Learn to Program in {Language}" books that are designed to teach you Visual Studio while building up your coding skills. I HIGHLY recommend dropping by the bookstore or library.
At the very least, you need to reduce the complexity of your calculation process. You need to learn how to take the value in A, add it to B and display it in C - before trying to do 10 times that all in one method. As I have mentioned before, having the entire process in one method means the method fails as soon as you have one back step.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Aspersion |
last post by:
I'm building an ASP page that has a lot of text and graphics.
There is a calculation facility on the page. The user enters several
numbers in a form and presses a button to see the calculated...
|
by: Michael G |
last post by:
double A = floor((2447297.0 - 122.1)/365.25);
i get differing results. It varies between 6699 and 6700. The correct
answer is 6699.
The 6700 result really throws the entire group of calculations...
|
by: anaxamandr |
last post by:
Hi.
I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process.
I attempted...
|
by: gavo |
last post by:
Hi.
using A2K; i have a form containing a continous subform. The question is,
how can i call a calculation for one of the fields in the continous subform
from the main form.
At the moment i...
|
by: Michiel Alsters |
last post by:
Hello everybody,
I hope anybody can help me. I'll try to give a brief overview of my
problem. I have running a program that performs a heavy calculation.
To give the user feedback what the...
|
by: th-ko |
last post by:
Hi,
I would like to know whether a certain coding pattern exist to handle
the following problem.
I am using a const methode to get and value a from the class. In case
the value was not calculated...
|
by: 60325 |
last post by:
This is the page where I collect the data in drop-down boxes with
values of 1-10 and send it to a submitted page to do calculations.
Example:
Employee1 TeamScore(1-10)
Employee2 ...
|
by: The alMIGHTY N |
last post by:
Hi all,
Let's say I have a simple math formula:
sum (x * y / 1000) / (sum z / 1000)
I have to do this across 50 items, each with an x, y and z value, when
the page first loads AND when a...
|
by: mattmao |
last post by:
Okay, I was asked by a friend about the result of this limit:
http://bbs.newwise.com/attdata/forumid_14/20070922_fe7f77c81050413a20fbDWYOGm7zeRj3.jpg
Not n->zero but n-> + infinite
I really...
|
by: csolomon |
last post by:
I have an unbound text box which I use to get a calculation, called DM_SampleWt. This text box's control source is:
=GetSize(,Nz(,0),.!,.!.(2))
I have written a function that will get the required...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |