|
I am new to C# and have a class project to work on. I am trying to create an Amortization calulator the display the payment results based on the Time period thay have to repay the loan. The calculation part of it is working fine but I can not get it to display the result. Can I please get some help with this? See code Below:
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Label6.Text = "Final Balance: " +
CalculateBalance(Convert.ToInt32(TextBox1.Text),
(Convert.ToDouble(TextBox2.Text) / 100),
Convert.ToInt32(TextBox3.Text),
Convert.ToInt16(DropDownList1.SelectedItem.Value)).ToString();
}
private string CalculateBalance(int Principal, double Rate, int Years, int Period)
{
double result;
double NumToBeRaised = (1 + Rate / Period);
result=Principal * System.Math.Pow(NumToBeRaised, (Years * Period));
return (result.ToString("C"));
}
private string AmortDisplay(double Principal, double results, int Years, int Period)
{
int AmortTime;
double AmortPayment;
double RemBalance;
string Output;
AmortTime = (Years * Period);
AmortPayment = (results / AmortTime);
RemBalance = -(Principal - AmortPayment);
TextBox4.Text = "Duration\t \tPayment\t \tRemaining Balance \n" + AmortTime + "\t\t" + Convert.ToString(AmortPayment) + "\t\t" + Convert.ToString(RemBalance) + "\n";
}
protected void Button2_Click(object sender, EventArgs e)
{
AmortDisplay(Convert.ToDouble(TextBox1.Text),
Convert.ToDouble(Label6.Text),
Convert.ToInt32(TextBox3.Text),
Convert.ToInt16(DropDownList1.SelectedItem.Value)).ToString();
}
</script>
Greg
The Belizean Dan Dada!!!
|
|
|
|
|
Skanless wrote: Can I please get some help with this?
Someone might help you, especially if you post a question or problem instead of just saying "I can not get it to display the result."
:josh:
My WPF Blog[^]
|
|
|
|
|
this is a re-post. I would suggest that you read 'how to get an answer to your question' at the top of the forum. I am sure that someone could answer a question for you if you ventured to actually ask a question, provide some detail, etc...
cje
|
|
|
|
|
The code you posted will not compile. The function AmortDisplay, as written, does not return a value but is declared as returning a string.
In the calculation of Textbox4.text, AmortTime is not converted to a string.
This would be better done using String.Format anyway.
There is no error handling (try...catch) to capture conversion errors,
so any exception will just propagate up to the top and crash...
Why do you convert the result of CalculateBalance nto a string
(as the return value) and then immediatly convert it back
to a double in order to pass it to AmmortDisplay?
Clean up your code. avoid conversion operations in the parameters passed
to a function (do these as separate steps with local values,
pass the local values) - this:
AmortDisplay(Convert.ToDouble(TextBox1.Text),
Convert.ToDouble(Label6.Text),
Convert.ToInt32(TextBox3.Text),
Convert.ToInt16(DropDownList1.SelectedItem.Value)).ToString();
will be very hard to debug, and there are at least 5 opportunities
for a mistyped (or empty) entry field to cause an exception to be thrown
in that single function call.
Why the .ToString() at the end? the function called should have returned a string
(and would have, but you left out the return statement) anyway..
You definately need to study harder. This is really poor code, and would be unacceptable
in any production work.
Some advice:
1. Keep it simple, avoid complex function calls with nested calls
2. do things in clear descrete steps so you can inspect each easily.
3. don't change data types any earlier than necessary.
4. inspect your code with the presumption that there is a stupid error or oversight,
the best of us still make these occaisionally.
|
|
|
|
|
Why don't you follow up on the replies you get, instead of posting the question again?
---
b { font-weight: normal; }
|
|
|
|
|
Hello,
I have 2 treeView controls on my form. Can you please tell me how can I copy all the nodes with the same structure from treeView1 to treeView2?
Note: I'm using .NET 2005.
Your help would be greatly appreciated.
|
|
|
|
|
treeView2.Nodes.Clear();
foreach(TreeNode node in treeView1.Nodes){
treeView2.Nodes.Add(node);
}
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Thanks but I got:
Cannot add or insert the item 'Dogs & Cats' in more than one place. You must first remove it from its current location or clone it.
Parameter name: node
|
|
|
|
|
AngryC wrote: You must first remove it from its current location or clone it.
I'm gonna take a stab in the dark and suggest TreeNode.Clone() .
foreach (TreeNode tn in treeView1.Nodes) {
treeView2.Nodes.Add(tn.Clone() as TreeNode);
}
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
Hi, Does anybody know how to make a TextBox Array in a C#.NET Web Application?
And for CheckBoxes?
Oren,
|
|
|
|
|
TextBox[] tb = new TextBox[3];
CheckBox[] cb = new CheckBox[3];
:josh:
My WPF Blog[^]
|
|
|
|
|
Ok... I would have not think it was so simple, .
Thanks!
Oren,
|
|
|
|
|
hi i had get the color through color dialog box and saved them in database nd then i want to set on the form?
then i want to set the color of dalog reading from the datbase but it gives error that cannot change readonly property.
System.drawing.color clr=new color();
clr.A=a;//read from db; //gives error that cannot change readonly property
.R=b;
.B=v//et
now i want to set the form color to this.
this.color=clr;
how to assign values to color variables?
Tasleem Arif
|
|
|
|
|
Color is a struct and therefore mutable, supply values to it's static FromArgb method instead of trying to set properties after initialization.
Color c = Color.FromArgb(r, g, b);
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
as it is more suited to saving in a database.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
BoneSoft wrote: Color is a struct and therefore mutable,
You're correct in this case (if you prepend "im" to the word "mutable"), but structs in general are not necessarily immutable. Immutability of structs is a best practice, not a rule.
:josh:
My WPF Blog[^]
|
|
|
|
|
Woops! My intellisence ain't working today. Thanks for catching that.
And my understanding was that all structs are immutable, trying to change them just creates and swaps a new one behind the scenes, like strings or any other stacked value. So they seem to be mutable, though technically they are not. Maybe I have it wrong...
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
BoneSoft wrote: And my understanding was that all structs are immutable, trying to change them just creates and swaps a new one behind the scenes, like strings or any other stacked value
Structs (aka 'value types') are copied by reference, but that doesn't imply immutability.
This code creates a Point struct and modifies it (not a copy of it):
Point pt = new Point(1,1);
pt.X = 2;
:josh:
My WPF Blog[^]
|
|
|
|
|
Can you group together CheckBoxes so only one in a group is checked at one time and if so How?
|
|
|
|
|
Winforms or ASP.NET?
If Winforms:
Use RadioButtons instead of CheckBoxs. Put them in a GroupBox or Panel and they'll automatically be mutually exclusive.
:josh:
My WPF Blog[^]
|
|
|
|
|
Winforms, and i can't use Radion buttons because i am looking for the sticky button look that a check box has.
|
|
|
|
|
Your users will be confused by mutually exclusive checkboxes. It's atypical and, hence, weird. When it comes to UIs, stick to conventions unless you have a very good reason not to.
:josh:
My WPF Blog[^]
|
|
|
|
|
What the hell is "sticky button look"? Can I use that next time I'm at the pool?
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
You deserve to be thrown off a cliff for doing so. Check box are designed so you can select multiple. Options are designed to choose. Switching the two will only confuse people.
That said, create a collection of all of the check boxes you want to enforce one check only. Add a listener to all the check boxes for CheckedChanged to the same method. In the method loop through all of the check boxes in the collection if the sender object is a check box that is true and set all other check boxes to unchecked.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
private void checkBox_CheckedChanged(object sender, EventArgs e) {
if(sender is CheckBox){
if(((CheckBox)sender).Checked){
foreach(CheckBox ck in list){
if(ck != sender){
ck.Checked = false;
}
}
}
}
}
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|