Register for your free account! | Forgot your password?

You last visited: Today at 04:10

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C# Help Please

Discussion on C# Help Please within the SRO Coding Corner forum part of the Silkroad Online category.

Closed Thread
 
Old   #1
 
djb's Avatar
 
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!
djb is offline  
Old 01/23/2011, 17:14   #2
 
lesderid's Avatar
 
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;
}
lesderid is offline  
Thanks
1 User
Old 01/23/2011, 17:21   #3
 
djb's Avatar
 
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!
djb is offline  
Old 01/23/2011, 17:55   #4
 
djb's Avatar
 
elite*gold: 0
Join Date: Apr 2007
Posts: 314
Received Thanks: 52
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
djb is offline  
Old 01/23/2011, 18:06   #5
 
lesderid's Avatar
 
elite*gold: 0
Join Date: Dec 2007
Posts: 2,400
Received Thanks: 1,517
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.
lesderid is offline  
Thanks
1 User
Old 01/23/2011, 18:36   #6
 
djb's Avatar
 
elite*gold: 0
Join Date: Apr 2007
Posts: 314
Received Thanks: 52
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!
djb is offline  
Old 01/23/2011, 19:04   #7
 
lesderid's Avatar
 
elite*gold: 0
Join Date: Dec 2007
Posts: 2,400
Received Thanks: 1,517
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!
lesderid is offline  
Thanks
1 User
Old 01/23/2011, 19:28   #8
 
djb's Avatar
 
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
djb is offline  
Old 01/23/2011, 19:42   #9
 
lesderid's Avatar
 
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.
lesderid is offline  
Thanks
1 User
Old 01/23/2011, 19:43   #10
 
djb's Avatar
 
elite*gold: 0
Join Date: Apr 2007
Posts: 314
Received Thanks: 52
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
djb is offline  
Old 01/23/2011, 22:01   #11
 
lesderid's Avatar
 
elite*gold: 0
Join Date: Dec 2007
Posts: 2,400
Received Thanks: 1,517
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)
lesderid is offline  
Thanks
1 User
Closed Thread




All times are GMT +1. The time now is 04:12.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.