vb.net “从字符串“”到类型“整数”的转换无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16655286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 13:39:56 来源:igfitidea点击:
"Conversion from string "" to type 'Integer' is not valid
提问by Raj Sharma
i am getting error in 1st line
我在第一行出错
Dim result = (CInt(Split(Overtime.Text, ":")(0)) * 60 + CInt(Split(Overtime.Text, ":")(1)))
OvertimeAmount.Text = (result * Val(OvertimeRate.Text)) / 60
回答by sanjeev
Dim i As Integer
Integer.TryParse(value, i)
Console.WriteLine("Integer:", i)
回答by tinstaafl
perhaps something like this will work:
也许这样的事情会奏效:
Dim Result as Integer = TimeSpan.Parse(Overtime.Text).TotalMinutes
OvertimeAmount.Text = ((result * Val(OvertimeRate.Text)) / 60).ToString
This assumes you are validating the text in Overtime. If not you can use the TryParse method.
这假设您正在验证加班文本。如果没有,您可以使用 TryParse 方法。
Dim ts As New TimeSpan
Dim ValidText As Boolean = TimeSpan.TryParse(Overtime.Text, ts)
If ValidText Then
Dim Result as Integer = ts.TotalMinutes
End If
回答by Legionair
To convert a string containing a numeric value to an actual numerical type (eg int) you need to use
要将包含数值的字符串转换为实际的数值类型(例如 int),您需要使用
Integer.Parse(someString)

