本文介绍了将String转换为Integer时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试将字符串转换为整数。 使用的代码是: Dim PStab As 整数 PStab = Convert.ToInt32(P1Stab1.Text) P1Stab1是一个标签。 当我加载表单时,我收到此错误; mscorlib.dll中出现System.FormatException类型的异常但未在用户代码中处理 附加信息:输入字符串的格式不正确。 在另一个子例程中,我使用了 Convert.ToInt32()将18个标签的内容转换为整数(包括Convert.ToInt32(P1Stab1.Text))的问题,以便我可以将它们一起添加。使用的代码是: 公共 PlayersTotal As Integer PlayersTotal = Convert.ToInt32(P1Stab1.Text)+ Convert.ToInt32(P1Stab2。文本)+ Convert.ToInt32(P1Stab3.Text)+ Convert.ToInt32(P1Stab4.Text)+ Convert.ToInt32(P1Stab5.Text)+ Convert.ToInt32(P1Stab6.Text)+ Convert.ToInt32(P1Stab7.Text)+转换。 ToInt32(P1Stab8.Text)+ Convert.ToInt32(P1Stab9.Text)+ Convert.ToInt32(P1Stab10.Text)+ Convert.ToInt32(P1Stab11.Text)+ Convert.ToInt32(P1Stab12.Text)+ Convert.ToInt32(P1Stab13.Text )+ Convert.ToInt32(P1Stab14.Text)+ Convert.ToInt32(P1Stab15.Text)+ Convert.ToInt32(P1Stab16.Text)+ Convert.ToInt32(P1Stab17.Text)+ Convert.ToInt32(P1Stab18.Text) 所以任何人都可以帮忙解决问题吗? 注意:当时加载表单标签默认为0(零)解决方法案例 I am trying to convert a string to an integer.The code used is;Dim PStab As Integer PStab = Convert.ToInt32(P1Stab1.Text)P1Stab1 is a label.When I load the form I get this error;An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user codeAdditional information: Input string was not in a correct format.In another subroutine I have used Convert.ToInt32() with no problems to convert the contents of 18 labels to integer (including Convert.ToInt32(P1Stab1.Text)) so I can add them together. The code used is;Public PlayersTotal As IntegerPlayersTotal = Convert.ToInt32(P1Stab1.Text) + Convert.ToInt32(P1Stab2.Text) + Convert.ToInt32(P1Stab3.Text) + Convert.ToInt32(P1Stab4.Text) + Convert.ToInt32(P1Stab5.Text) + Convert.ToInt32(P1Stab6.Text) + Convert.ToInt32(P1Stab7.Text) + Convert.ToInt32(P1Stab8.Text) + Convert.ToInt32(P1Stab9.Text) + Convert.ToInt32(P1Stab10.Text) + Convert.ToInt32(P1Stab11.Text) + Convert.ToInt32(P1Stab12.Text) + Convert.ToInt32(P1Stab13.Text) + Convert.ToInt32(P1Stab14.Text) + Convert.ToInt32(P1Stab15.Text) + Convert.ToInt32(P1Stab16.Text) + Convert.ToInt32(P1Stab17.Text) + Convert.ToInt32(P1Stab18.Text)So can anyone help with what is going wrong?Note: At the time of loading the form the labels are defaulted to 0(zero) 解决方案 这篇关于将String转换为Integer时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-04 03:04