0

I have 3 text boxes 1TB,2TB and 3TB. I would like to multiply 1TB by 2TB and put the answer in 3TB. Can anyone help me with this code. Im new to C# and I keep getting errors.
Thanks in advance.

4
Contributors
9
Replies
12
Views
8 Years
Discussion Span
Last Post by ddanbe
0

I just used those names on the forum the real text boxes are properly labeled.

0
Int32 res=Int32.Parse(textBox1.Text);
res=res*Int32.Parse(textBox2.Text);
textBox3.Text=res.ToString();
0

For school work that is fine. For real world, you should use Int32.TryParse because you never know what will be in those text boxes.

int result_1;
int result_2;
if (Int32.TryParse(textBox1.Text, out result_1)
     && Int32.TryParse(textBox2.Text, out result_2))
{
      textBox3.Text = (result_1 * result_2).ToString();
}
0
Int32 res=Int32.Parse(textBox1.Text);
res=res*Int32.Parse(textBox2.Text);
textBox3.Text=res.ToString();

What if they are decimals?

0

How do I only allow numeric in the text box?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.