|
You last visited: Today at 04:10
Advertisement
C# Help Please
Discussion on C# Help Please within the SRO Coding Corner forum part of the Silkroad Online category.
01/23/2011, 16:29
|
#1
|
elite*gold: 0
Join Date: Apr 2007
Posts: 314
Received Thanks: 52
|
C# Help Please
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
|
#2
|
elite*gold: 0
Join Date: Dec 2007
Posts: 2,400
Received Thanks: 1,517
|
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
|
#3
|
elite*gold: 0
Join Date: Apr 2007
Posts: 314
Received Thanks: 52
|
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
|
#4
|
elite*gold: 0
Join Date: Apr 2007
Posts: 314
Received Thanks: 52
|
Quote:
Originally Posted by lesderid
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
|
#5
|
elite*gold: 0
Join Date: Dec 2007
Posts: 2,400
Received Thanks: 1,517
|
Quote:
Originally Posted by djb
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
|
#6
|
elite*gold: 0
Join Date: Apr 2007
Posts: 314
Received Thanks: 52
|
Quote:
Originally Posted by lesderid
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
|
#7
|
elite*gold: 0
Join Date: Dec 2007
Posts: 2,400
Received Thanks: 1,517
|
Quote:
Originally Posted by djb
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
Thanks so much for your help!
|
Hah, no problem.
Edit: 1337th post!
|
|
|
01/23/2011, 19:28
|
#8
|
elite*gold: 0
Join Date: Apr 2007
Posts: 314
Received Thanks: 52
|
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
Uploaded with
|
|
|
01/23/2011, 19:42
|
#9
|
elite*gold: 0
Join Date: Dec 2007
Posts: 2,400
Received Thanks: 1,517
|
You have to place it at the beginning of the submit_Click method, before the variable declarations.
|
|
|
01/23/2011, 19:43
|
#10
|
elite*gold: 0
Join Date: Apr 2007
Posts: 314
Received Thanks: 52
|
Quote:
Originally Posted by lesderid
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
|
#11
|
elite*gold: 0
Join Date: Dec 2007
Posts: 2,400
Received Thanks: 1,517
|
Quote:
Originally Posted by djb
ah ha! you're the best, thanks so much!
|
No problem. Glad I could help you. ^^
#Reported: Close Request (Question Answered)
|
|
|
All times are GMT +1. The time now is 04:12.
|
|