Newvie - String to Int conversion

  • Thread starter Thread starter Stig Nordlander
  • Start date Start date
S

Stig Nordlander

I'd like to enter a numeric value in a textbox and use the value in a
calculation but I can't get it to work

int X
X = textBox1;


I get the error message

Cannot implicity convert type 'System.Windows.Forms.TextBox' to 'int'

What must I do to make it work?
 
First, you must use the .Text property on TextBox.

Next use the static Parse method on int, thusly:

int x = int.Parse(textBox1.Text);

Hope this helps
Brian W
 
Thanks, it works.

Stig

Brian W said:
First, you must use the .Text property on TextBox.

Next use the static Parse method on int, thusly:

int x = int.Parse(textBox1.Text);

Hope this helps
Brian W
 
Back
Top