字符串格式错误 [英] incorrect string format

查看:78
本文介绍了字符串格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道这个小组是否涵盖了网络应用程序,但这里有。在VS 2005中,我在

服务器的回发期间试图获取变量以保存其值。

我将文本框的用户键值转换为整数并将其分配给模块级变量,然后将变量转换为

隐藏文本框,将其EnableViewState设置为true,以便返回

重新加载。然后在''load事件的形式中,我尝试将隐藏文本框的内容转换为整数:


intTotalCredits = Integer。解析(Me.txtAccumCredits.Text)


并将其分配回变量并得到格式异常:


"输入字符串格式不正确。


我也尝试过使用label.Text和HiddenField.Value;相同的

例外。我注意到代码行在sub中工作正常,但在load事件中没有。什么给了?


很多人,


Ripper


PS:我在关注VB教科书中的说明。我很震惊,没有比这更容易的方法。据我所知,曾经有一个模块可用

与网页无关,发生了什么事?

Don''t know if this group covers web apps, but here goes. In VS 2005, I am
trying to get variables to hold thier values during postback from the
server. I convert a text box''s user-keyed value to an integer and assign it
to a module level variable, then convert the variable and assign it to a
hidden text box, setting it''s EnableViewState to true so it returns with the
reload. Then in the form''s load event, I attempt to convert the contents of
the hidden textbox back to an integer thus:

intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)

and assign it back to the variable and I get a format exception:

"Input String was not in correct format."

I''ve also tried this with a label.Text and the HiddenField.Value; same
exception. I noticed that the line of code works fine in a sub, but not in
the load event. What gives?

Many thanx,

Ripper

PS: I''m following instructions in a VB textbook. I''m astounded there isn''t
an easier way to do this. I understand there used to be a module available
that was unassociated with the web page, what happened to that?

推荐答案

问题是:


intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)


如果有没有数字进入文本框?您是否在此文本框上使用

验证控件以确保只输入数字数据?


使用:intTotalCredits = CType(txtAccumCredits.Text,Integer)代替


另外(我不能不问),你在这里尝试做什么?它好像你需要花费很多精力来完成ASP.NET已经做的事情。

。您只想将相同的数据发回给客户端吗?b
发布到服务器上? EnableViewState为您完成此操作,无需代码

即将推出。


" RipperT @ comcast.net>" < rippert< nospamwrote in message

news:%2 **************** @ TK2MSFTNGP02.phx.gbl ...
The problem is this:

intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)

What if there is no number entered into the textbox though? Are you using a
validation control on this textbox to ensure only numeric data is entered?

Use: intTotalCredits = CType(txtAccumCredits.Text, Integer) instead

Also (I can''t help but to ask), What are you attempting to do here? It
seems like you are going to great lengths to to what ASP.NET already does
for you. You just want to send back down to the client the same data it
posted up to the server? EnableViewState does this for you with no code
what-so-ever.

"RipperT @comcast.net>" <rippert<nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...

不知道这个小组是否涵盖了网络应用程序,但现在就去了。在VS 2005中,我在

服务器的回发期间试图获取变量以保存其值。

我将文本框的用户键值转换为整数并将其分配给模块级变量,然后转换变量并将其分配给

a隐藏文本框,将它的EnableViewState设置为true,这样它返回

重新加载。然后在''load事件的形式中,我尝试将隐藏文本框的

内容转换回整数:


intTotalCredits = Integer。解析(Me.txtAccumCredits.Text)


并将其分配回变量并得到格式异常:


"输入字符串格式不正确。


我也尝试过使用label.Text和HiddenField.Value;相同的

例外。我注意到代码行在sub中工作正常,但在load事件中没有。什么给了?


很多人,


Ripper


PS:我在关注VB教科书中的说明。我很震惊,没有比这更容易的方法。我知道曾经有一个模块可用

与网页无关,发生了什么?
Don''t know if this group covers web apps, but here goes. In VS 2005, I am
trying to get variables to hold thier values during postback from the
server. I convert a text box''s user-keyed value to an integer and assign
it to a module level variable, then convert the variable and assign it to
a hidden text box, setting it''s EnableViewState to true so it returns with
the reload. Then in the form''s load event, I attempt to convert the
contents of the hidden textbox back to an integer thus:

intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)

and assign it back to the variable and I get a format exception:

"Input String was not in correct format."

I''ve also tried this with a label.Text and the HiddenField.Value; same
exception. I noticed that the line of code works fine in a sub, but not in
the load event. What gives?

Many thanx,

Ripper

PS: I''m following instructions in a VB textbook. I''m astounded there isn''t
an easier way to do this. I understand there used to be a module available
that was unassociated with the web page, what happened to that?



响应的许多thanx。对不起,我已经省略了解释。这是一个

类作业。我试图积累总数,如

intTotalCredits + = intCredits,所以我必须在回发时保留变量

intTotalCredits。


我会尝试你的建议。我还注意到我正在使用

form_load事件而不是page_load事件。不知道这是否会产生

的差异,但会发现!我在这吃鱼。


再次谢谢,


Rip

" Scott M." ; < s - *** @ nospam.nospamwrote in message

news:Om ************** @ TK2MSFTNGP02.phx.gbl ...
Many thanx for the response. Sorry I''ve omitted an explanation. This is a
class assignment. I am attempting to accumulate totals, as in
intTotalCredits += intCredits, so I''ve got to retain the variable
intTotalCredits on postback.

I will try your suggestion. I''ve also just noticed that I am using the
form_load event instead of the page_load event. Don''t know if that makes a
difference, but will find out! I''m a fish at this.

Thanx again,

Rip
"Scott M." <s-***@nospam.nospamwrote in message
news:Om**************@TK2MSFTNGP02.phx.gbl...

问题是:


intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)


如果文本框中没有输入数字怎么办?您是否在此文本框中使用

a验证控件以确保只输入数字数据




使用:intTotalCredits = CType( txtAccumCredits.Text,Integer)而不是


另外(我不能不问),你在这里尝试做什么?它好像你需要花费很多精力来完成ASP.NET已经做的事情。

。您只想将相同的数据发回给客户端吗?b
发布到服务器上? EnableViewState为您完成此操作,无需代码

即将推出。


" RipperT @ comcast.net>" < rippert< nospamwrote in message

news:%2 **************** @ TK2MSFTNGP02.phx.gbl ...
The problem is this:

intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)

What if there is no number entered into the textbox though? Are you using
a validation control on this textbox to ensure only numeric data is
entered?

Use: intTotalCredits = CType(txtAccumCredits.Text, Integer) instead

Also (I can''t help but to ask), What are you attempting to do here? It
seems like you are going to great lengths to to what ASP.NET already does
for you. You just want to send back down to the client the same data it
posted up to the server? EnableViewState does this for you with no code
what-so-ever.

"RipperT @comcast.net>" <rippert<nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...

>不知道这个小组是否涵盖了网络应用程序,但现在就去了。在VS 2005中,我试图在
服务器回发期间获取变量来保存它们的值。我将文本框的用户键值转换为整数并将其分配给模块级变量,然后转换变量并将其分配给隐藏文本框,将其设置为'' EnableViewState为true,因此它会在重新加载时返回
。然后在''load事件的形式中,我尝试将隐藏文本框的
内容转换回整数:

intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)

并将其分配给变量,我得到格式异常:

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

我也尝试过使用label.Text和HiddenField.Value;同样的例外。我注意到代码行在sub中工作正常,但在load事件中没有
。什么给了?

很多人,开膛手

PS:我正在按照VB教科书中的说明进行操作。我很震惊
这不是一个更容易的方法。据我所知,曾经有一个与网页无关的模块,发生了什么事?
>Don''t know if this group covers web apps, but here goes. In VS 2005, I am
trying to get variables to hold thier values during postback from the
server. I convert a text box''s user-keyed value to an integer and assign
it to a module level variable, then convert the variable and assign it to
a hidden text box, setting it''s EnableViewState to true so it returns
with the reload. Then in the form''s load event, I attempt to convert the
contents of the hidden textbox back to an integer thus:

intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)

and assign it back to the variable and I get a format exception:

"Input String was not in correct format."

I''ve also tried this with a label.Text and the HiddenField.Value; same
exception. I noticed that the line of code works fine in a sub, but not
in the load event. What gives?

Many thanx,

Ripper

PS: I''m following instructions in a VB textbook. I''m astounded there
isn''t an easier way to do this. I understand there used to be a module
available that was unassociated with the web page, what happened to that?




intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)不起作用:


" from type string""到''整数''是无效的'


正如我所说,如果我把它放在一个子中,它可以工作,但它在负载中不起作用
活动。我只是没有得到它。

如果有人有任何想法,请帮忙!谢谢!


Rip


" RipperT" < Ri ***** @ Nowhere.com写了留言

news:ua ************** @ TK2MSFTNGP03.phx.gbl ...
intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text) does not work:

"Conversion from type string "" to ''integer'' is not valid"

As I said, if I put it in a sub, it works, but it doesn''t work in the load
event. I just don''t get it.
If anyone has any ideas, please help! And thanks!

Rip

"RipperT" <Ri*****@Nowhere.comwrote in message
news:ua**************@TK2MSFTNGP03.phx.gbl...

响应的多个thanx。对不起,我已经省略了解释。这是一个

类作业。我试图积累总数,如

intTotalCredits + = intCredits,所以我必须在回发时保留变量

intTotalCredits。


我会尝试你的建议。我还注意到我正在使用

form_load事件而不是page_load事件。不知道这是否会产生

的差异,但会发现!我是这样的鱼。


再次谢谢,


Rip


" Scott M. < s - *** @ nospam.nospamwrote in message

news:Om ************** @ TK2MSFTNGP02.phx.gbl ...
Many thanx for the response. Sorry I''ve omitted an explanation. This is a
class assignment. I am attempting to accumulate totals, as in
intTotalCredits += intCredits, so I''ve got to retain the variable
intTotalCredits on postback.

I will try your suggestion. I''ve also just noticed that I am using the
form_load event instead of the page_load event. Don''t know if that makes a
difference, but will find out! I''m a fish at this.

Thanx again,

Rip
"Scott M." <s-***@nospam.nospamwrote in message
news:Om**************@TK2MSFTNGP02.phx.gbl...

>问题是:

intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)

如果虽然文本框中没有输入数字?您是否在此文本框中使用验证控件以确保仅输入数字数据?

使用:intTotalCredits = CType(txtAccumCredits.Text,Integer)而不是

另外(我不能不问),你在这里尝试做什么?看起来你似乎已经不遗余力地为ASP.NET做了什么。您只想将发布到服务器的相同数据发送回客户端? EnableViewState为您完成此操作,无需任何代码
即时通讯。

RipperT @ comcast.net> < rippert< nospamwrote in message
新闻:%2 **************** @ TK2MSFTNGP02.phx.gbl ...
>The problem is this:

intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)

What if there is no number entered into the textbox though? Are you
using a validation control on this textbox to ensure only numeric data is
entered?

Use: intTotalCredits = CType(txtAccumCredits.Text, Integer) instead

Also (I can''t help but to ask), What are you attempting to do here? It
seems like you are going to great lengths to to what ASP.NET already does
for you. You just want to send back down to the client the same data it
posted up to the server? EnableViewState does this for you with no code
what-so-ever.

"RipperT @comcast.net>" <rippert<nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...

>>不知道这个小组是否涵盖了网络应用程序,但现在就去了。在VS 2005中,我试图在
服务器回发期间获取变量来保存它们的值。我将文本框的用户键值转换为整数并将其分配给模块级变量,然后转换变量并将其分配给隐藏文本框,将其设置为'' EnableViewState为true,因此它会在重新加载时返回
。然后在''load事件的形式中,我尝试将隐藏文本框的
内容转换回整数:

intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)

并将其分配给变量,我得到格式异常:

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

我也尝试过使用label.Text和HiddenField.Value;同样的例外。我注意到代码行在sub中工作正常,但在load事件中没有
。什么给了?

很多人,开膛手

PS:我正在按照VB教科书中的说明进行操作。我很震惊
这不是一个更容易的方法。据我所知,曾经有一个与网页无关的模块,发生了什么?
>>Don''t know if this group covers web apps, but here goes. In VS 2005, I
am trying to get variables to hold thier values during postback from the
server. I convert a text box''s user-keyed value to an integer and assign
it to a module level variable, then convert the variable and assign it
to a hidden text box, setting it''s EnableViewState to true so it returns
with the reload. Then in the form''s load event, I attempt to convert the
contents of the hidden textbox back to an integer thus:

intTotalCredits = Integer.Parse(Me.txtAccumCredits.Text)

and assign it back to the variable and I get a format exception:

"Input String was not in correct format."

I''ve also tried this with a label.Text and the HiddenField.Value; same
exception. I noticed that the line of code works fine in a sub, but not
in the load event. What gives?

Many thanx,

Ripper

PS: I''m following instructions in a VB textbook. I''m astounded there
isn''t an easier way to do this. I understand there used to be a module
available that was unassociated with the web page, what happened to
that?





这篇关于字符串格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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