By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

textbox text to int error

P: n/a
I can't get a number out of my textbox. it keeps giving me an error and
saying that the input string was not in the correct format.

this.number = int.Parse((this.numberTextBox.Text.ToString());

How do I get the number out of the text box if I only entered small positive
integers?

dave
Nov 15 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
There looks to be too many brackets (parentheseseeses) in your code line
below, that would be my first place to check. Change that to:

this.number = int.Parse( this.numberTextBox.Text.ToString() );

then see if you still have the same problem. It might also be wise to check
that the text box has some text in before you try and convert it to an int.
So the below might be even better still:

if( this.numberTextBox.Text != string.Empty )
{
this.number = int.Parse( this.numberTextBox.Text );
}


"Dave" <da*********@hotmail.com> wrote in message
news:98********************@comcast.com...
I can't get a number out of my textbox. it keeps giving me an error and
saying that the input string was not in the correct format.

this.number = int.Parse((this.numberTextBox.Text.ToString());

How do I get the number out of the text box if I only entered small positive integers?

dave

Nov 15 '05 #2

P: n/a
Generally when I know a certain TextBox will only be able to take Int's I
pass it through a regex function to validate it and then I parse it from
string to int... I alos place a zero as the default text for the TextBox
this way (if you dont use regex) u can make sure that the field will never
be empty (unless changed, thats where regex comes in ;))
"Mark Sizer" <bl**@blah.com> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
There looks to be too many brackets (parentheseseeses) in your code line
below, that would be my first place to check. Change that to:

this.number = int.Parse( this.numberTextBox.Text.ToString() );

then see if you still have the same problem. It might also be wise to check that the text box has some text in before you try and convert it to an int. So the below might be even better still:

if( this.numberTextBox.Text != string.Empty )
{
this.number = int.Parse( this.numberTextBox.Text );
}


"Dave" <da*********@hotmail.com> wrote in message
news:98********************@comcast.com...
I can't get a number out of my textbox. it keeps giving me an error and
saying that the input string was not in the correct format.

this.number = int.Parse((this.numberTextBox.Text.ToString());

How do I get the number out of the text box if I only entered small

positive
integers?

dave


Nov 15 '05 #3

P: n/a
nevermind, I figured it out after several days :) It was just that I
disposed the textbox before I got the number out of it. so now I have the
dispose function at the end of that function instead of at the beginning
thanks anyway
dave

"Dave" <da*********@hotmail.com> wrote in message
news:98********************@comcast.com...
I can't get a number out of my textbox. it keeps giving me an error and
saying that the input string was not in the correct format.

this.number = int.Parse((this.numberTextBox.Text.ToString());

How do I get the number out of the text box if I only entered small positive integers?

dave

Nov 15 '05 #4

P: n/a
"Dave" <da*********@hotmail.com> wrote:
I can't get a number out of my textbox. it keeps
giving me an error and saying that the input string
was not in the correct format.


int iValue = 0;

try
{
iValue = Convert.ToInt32(txtValue.Text);
}
catch
{
// Deal with strings that aren't valid integers
}

P.

--
www.CL4.org
Nov 15 '05 #5

P: n/a
Can you give an example regex validation method?

I do not understand regex at all!!

"Mitchell Geere" <mg****@telkomsa.net> wrote in message
news:OB**************@TK2MSFTNGP10.phx.gbl...
Generally when I know a certain TextBox will only be able to take Int's I
pass it through a regex function to validate it and then I parse it from
string to int... I alos place a zero as the default text for the TextBox
this way (if you dont use regex) u can make sure that the field will never
be empty (unless changed, thats where regex comes in ;))
"Mark Sizer" <bl**@blah.com> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
There looks to be too many brackets (parentheseseeses) in your code line
below, that would be my first place to check. Change that to:

this.number = int.Parse( this.numberTextBox.Text.ToString() );

then see if you still have the same problem. It might also be wise to

check
that the text box has some text in before you try and convert it to an

int.
So the below might be even better still:

if( this.numberTextBox.Text != string.Empty )
{
this.number = int.Parse( this.numberTextBox.Text );
}


"Dave" <da*********@hotmail.com> wrote in message
news:98********************@comcast.com...
I can't get a number out of my textbox. it keeps giving me an error and saying that the input string was not in the correct format.

this.number = int.Parse((this.numberTextBox.Text.ToString());

How do I get the number out of the text box if I only entered small

positive
integers?

dave



Nov 15 '05 #6

P: n/a
Please can you tell me which function converts integer to
string?You know,if I want to put a integer,lets say x,
variable to textbox1 what do I need to write?


.

Nov 15 '05 #7

P: n/a

"djozy" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
Please can you tell me which function converts integer to
string?You know,if I want to put a integer,lets say x,
variable to textbox1 what do I need to write?


.

that's easy. textbox.text = int1.ToString();
just put a dot on the end of the variable and the function ToString() and it
will convert it.
dave
Nov 15 '05 #8

P: n/a
Thank you.I am a begginer.I started with C# few days ago
Nov 15 '05 #9

P: n/a
I know how it is, I just started on it a couple months ago and I found it so
hard that I gave up on doing my project for a little bit. but I'll give you
some advice to help you learn fast.
open up a notepad on the computer and copy and paste little snippets of
code and where they go in there so that you don't ever have to memorize
anything to use it. you will learn very fast this way. look up stuff on the
internet and paste new things there.
also, getting microsoft visual studio will help A TON. trust me. for
example. if you wrote the name of the integer you were talking about and
then put a dot infront of it, it would list the functions that you can use.
and ToString() is one of them. so you would have found that without having
to ask on here. it will help you find lots of stuff you otherwise wouldn't
know how to use or see.
well, good luck
dave
"djozy" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
Thank you.I am a begginer.I started with C# few days ago

Nov 15 '05 #10

P: n/a
Here is a link to an article which will explain it to you rather well....

http://www.radsoftware.com.au/web/Co...xAdvanced.aspx
Mitch
"Paul R" <ro********@aol.com> wrote in message
news:eM*************@tk2msftngp13.phx.gbl...
Can you give an example regex validation method?

I do not understand regex at all!!

"Mitchell Geere" <mg****@telkomsa.net> wrote in message
news:OB**************@TK2MSFTNGP10.phx.gbl...
Generally when I know a certain TextBox will only be able to take Int's I
pass it through a regex function to validate it and then I parse it from
string to int... I alos place a zero as the default text for the TextBox
this way (if you dont use regex) u can make sure that the field will never be empty (unless changed, thats where regex comes in ;))
"Mark Sizer" <bl**@blah.com> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
There looks to be too many brackets (parentheseseeses) in your code line below, that would be my first place to check. Change that to:

this.number = int.Parse( this.numberTextBox.Text.ToString() );

then see if you still have the same problem. It might also be wise to

check
that the text box has some text in before you try and convert it to an

int.
So the below might be even better still:

if( this.numberTextBox.Text != string.Empty )
{
this.number = int.Parse( this.numberTextBox.Text );
}


"Dave" <da*********@hotmail.com> wrote in message
news:98********************@comcast.com...
> I can't get a number out of my textbox. it keeps giving me an error

and > saying that the input string was not in the correct format.
>
> this.number = int.Parse((this.numberTextBox.Text.ToString());
>
> How do I get the number out of the text box if I only entered small
positive
> integers?
>
> dave
>
>



Nov 15 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.