C# Help Please

01/23/2011 16:29 djb#1
Hey guys, this is unrelated to SRO but im desperate from help and i know everyone on this forum is really skilled. My computer science 101 class taught me c++ console programming, and now im in an ist class that assumes everyone knows object oriented c# programming. Im really unfamiliar with this and I'm unsure how to use it and im unsure of the syntax. Our assignment is to create an amortization program. It has 4 text boxes. The inputs are Principle, Rate, and Term of loan. The fourth textbox is for the output of the monthly payment that will be calculated from this program. So far what I've done is go into the Private function of each textbox and convert the string to double.
Double Principle = Convert.ToDouble(principle.Text) ;
However, now that I've done that I'm unsure of a few things, since each function for each object is private, how do i call variables from other objects. What i mean is, i have the formula for calculating the monthly payment, but im unsure where in the code to put the formula because if i put it in a private function somewhere, and i call the variable "principle" it doesnt recognize it.

After i get that squared away, im unsure how to code the "submit " button to provide the output in the fourth textbox.

Sorry thats alot, and again sorry this is unrelated to sro. I know the people here are really good and my teacher has yet to email me back and i really need help.
Thanks!
01/23/2011 17:14 lesderid#2
Post your code and I'll try to help ya.
EDIT: Maybe it's this easy:
Code:
public void SubmitButton_Click () //(assign this to the submit button's click event)
{
    Double principle = Convert.ToDouble(principleBox.Text);
    Double rate = Convert.ToDouble(rateBox.Text);
    Double termOfLoan = Convert.ToDouble(termOfLoanBox.Text);

    Double result = /* Replace this with your formula. */;
    
    resultBox.Text = result;
}
01/23/2011 17:21 djb#3
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace amortization
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void label2_Click(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{

}

private void label2_Click_1(object sender, EventArgs e)
{

}

private void label3_Click(object sender, EventArgs e)
{

}

private void rate_TextChanged(object sender, EventArgs e)
{
Double Rate = Convert.ToDouble(rate.Text);
}

private void principle_TextChanged(object sender, EventArgs e)
{
Double Principle = Convert.ToDouble(principle.Text);
}

private void term_TextChanged(object sender, EventArgs e)
{
Double Term = Convert.ToDouble(term.Text), Months;
Months = Term * 12;


}

private void payment_TextChanged(object sender, EventArgs e)
{



}

private void submit_Click(object sender, EventArgs e)
{

}


}
}


thank you!
01/23/2011 17:55 djb#4
Quote:
Originally Posted by lesderid View Post
Post your code and I'll try to help ya.
EDIT: Maybe it's this easy:
Code:
public void SubmitButton_Click () //(assign this to the submit button's click event)
{
    Double principle = Convert.ToDouble(principleBox.Text);
    Double rate = Convert.ToDouble(rateBox.Text);
    Double termOfLoan = Convert.ToDouble(termOfLoanBox.Text);

    Double result = /* Replace this with your formula. */;
    
    resultBox.Text = result;
}

Im not sure because apparently you cant output to a textbox unless its read only, so im supposed to output it to a label. Not sure how to do that
01/23/2011 18:06 lesderid#5
Quote:
Originally Posted by djb View Post
Im not sure because apparently you cant output to a textbox unless its read only, so im supposed to output it to a label. Not sure how to do that
Umm, you can output to a TextBox.
01/23/2011 18:36 djb#6
Quote:
Originally Posted by lesderid View Post
Umm, you can output to a TextBox.
ok i understand now, and i got it to work with a basic mutliplication formula. Now when i debugged it, if i didnt put an input value in each of the boxes it gave me an error. How do i code a statement that says "if there is no input give error "no input provided"
Thanks so much for your help!
01/23/2011 19:04 lesderid#7
Quote:
Originally Posted by djb View Post
How do i code a statement that says "if there is no input give error "no input provided"
Do this:
Code:
if (box1.Text == "" || box2.Text == "" || box3.Text == "") //Change Box names...
{
   MessageBox.Show("Please make sure you entered all the values!", "Error");
}
Or you could put it in a "try...catch..." statement. (google it)

Quote:
Originally Posted by djb View Post
Thanks so much for your help!
Hah, no problem.

Edit: 1337th post!
01/23/2011 19:28 djb#8
I did what you said for the error box and the program itself gives me an error before my error pops up. heres what happens

[Only registered and activated users can see links. Click Here To Register...]

Uploaded with [Only registered and activated users can see links. Click Here To Register...]
01/23/2011 19:42 lesderid#9
You have to place it at the beginning of the submit_Click method, before the variable declarations.
01/23/2011 19:43 djb#10
Quote:
Originally Posted by lesderid View Post
You have to place it at the beginning of the submit_Click method, before the variable declarations.
ah ha! you're the best, thanks so much!
lol.. congrats on your 1337 post
01/23/2011 22:01 lesderid#11
Quote:
Originally Posted by djb View Post
ah ha! you're the best, thanks so much!
No problem. Glad I could help you. ^^

#Reported: Close Request (Question Answered)