textbox text to int error [英] textbox text to int error

查看:78
本文介绍了textbox text to int error的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文本框中无法输入数字。它一直给我一个错误和

说输入字符串的格式不正确。


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


如果我只输入小的积极的

整数,如何从文本框中取出数字?


dave

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

推荐答案

代码行中有太多括号(parentheseseeses)

以下,这将是我的第一个检查位置。更改为:


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


然后看看你是否还有同样的问题。在尝试转换之前,检查文本框中是否包含一些文本可能也是明智之举

它是一个int。

所以下面可能会更好:


if(this.numberTextBox.Text!= string.Empty)

{

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

}



" Dave" <哒********* @ hotmail.com>在消息中写道

news:98 ******************** @ comcast.com ...
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无法从我的文本框中获取数字。它一直给我一个错误,并且说输入字符串的格式不正确。

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

如果我只输入小的
正整数,如何从文本框中取出数字?

dave
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



一般来说,当我知道某个TextBox只能接受Int'的时候我会通过正则表达式函数传递它来验证它和然后我将它从

字符串解析为int ...我将这个方式的一个零作为TextBox的默认文本

(如果你不使用正则表达式)你可以确保该字段永远不会是空的(除非更改,这是正则表达式所在的地方;))

Mark Sizer < BL ** @ blah.com>在消息中写道

新闻:Ox ************** @ TK2MSFTNGP09.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...
看起来也是如此您的代码行中有许多括号(parentheseseeses)
,这将是我的第一个检查位置。改为:

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

然后看看你是否还有同样的问题。在您尝试将其转换为
int之前,
检查文本框是否包含一些文本也可能是明智之举。所以下面的内容可能会更好:

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

戴夫 <哒********* @ hotmail.com>在消息中写道
新闻:98 ******************** @ comcast.com ...
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...
我不能从我的文本框中获取一个数字。它一直给我一个错误,并且说输入字符串的格式不正确。

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

如果我只输入小的
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


积极的

整数,如何从文本框中取出数字?

dave
integers?

dave




没关系,几天后我想出来:)这只是我

在我拿出号码之前处理了文本框。所以现在我在那个函数的末尾而不是在开头就有

dispose函数

非常感谢

dave


" Dave" <哒********* @ hotmail.com>在消息中写道

news:98 ******************** @ comcast.com ...
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无法从我的文本框中获取数字。它一直给我一个错误,并且说输入字符串的格式不正确。

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

如果我只输入小的
正整数,如何从文本框中取出数字?

dave
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



这篇关于textbox text to int error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆