need help with c#

Questions about programming languages and debugging
Locked
User avatar
kings2006
On the way to fame!
On the way to fame!
Posts: 47
Joined: 23 Apr 2007, 16:00
16

need help with c#

Post by kings2006 »

I need to convert into a string i believe.
int add;
add = textBox1.Text + textBox2.Text;
int subtract;
subtract = textBox1.Text - textBox2.Text;
int divide;
divide = textBox1.Text / textBox2.Text;
int multiply;
multiply = textBox1.Text * textBox2.Text;
help?????????????????????????????????????????????????????????????

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Re: need help with c#

Post by bubzuru »

kings2006 wrote:I need to convert into a string i believe.
int add;
add = textBox1.Text + textBox2.Text;
int subtract;
subtract = textBox1.Text - textBox2.Text;
int divide;
divide = textBox1.Text / textBox2.Text;
int multiply;
multiply = textBox1.Text * textBox2.Text;
help?????????????????????????????????????????????????????????????
i dont do c# but try

Code: Select all

int num1  = textBox1.Text;
int num2  = textBox2.Text;
int add   = num1 + num2;
etc etc

User avatar
kings2006
On the way to fame!
On the way to fame!
Posts: 47
Joined: 23 Apr 2007, 16:00
16

Post by kings2006 »

i tried and it gives me a error saying
Cannot implicitly convert type 'string' to 'int'

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Post by bubzuru »

kings2006 wrote:i tried and it gives me a error saying
Cannot implicitly convert type 'string' to 'int'
ok then try

Code: Select all

int num1  = Int.Parse(textBox1.Text);
int num2  = Int.Parse(textBox2.Text);
int add   = num1 + num2; 
if its not that then i don't know cuz i don't do c# sorry

User avatar
kings2006
On the way to fame!
On the way to fame!
Posts: 47
Joined: 23 Apr 2007, 16:00
16

Post by kings2006 »

thanks dude that works.

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Post by bubzuru »

kings2006 wrote:thanks dude that works.
np glad i could help :lol:

User avatar
Nerdz
The Architect
The Architect
Posts: 1127
Joined: 15 Jun 2005, 16:00
18
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:

Post by Nerdz »

bubzuru wrote:

Code: Select all

int num1  = Int.Parse(textBox1.Text);
int num2  = Int.Parse(textBox2.Text);
int add   = num1 + num2; 
now that you know this, you can do directly:

Code: Select all

int add = Int.Parse(textBox1.Text) + Int.Parse(textBox2.Text);
Also, don't forget to validate the key on input in your textbox...I think it's the propertie OnKeyPress(Object e)
if the char entered is higher than 47 and lower than 58
txtbox.text = txtbox.text + e.toString();

Something like this...
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.

User avatar
Sillymonkey
Newbie
Newbie
Posts: 2
Joined: 20 Jun 2008, 16:00
15

Post by Sillymonkey »

Also you can do this:

Code: Select all

int num1=Convert.ToInt32(textbox1.text)
If is doesn't work then try ToInt16 or 64.

User avatar
computathug
Administrator
Administrator
Posts: 2693
Joined: 29 Mar 2007, 16:00
17
Location: UK
Contact:

topic locked

Post by computathug »

I can see your just trying to help but did you actually see the date on this thread. Please dont revive dead posts, but hey welcome to the forum. :wink:

Locked