"从字符串转换""输入'整数'无效

时间:2013-05-20 17:52:03

标签: vb.net

我在第一行收到错误

Dim result = (CInt(Split(Overtime.Text, ":")(0)) * 60 + CInt(Split(Overtime.Text, ":")(1)))
OvertimeAmount.Text = (result * Val(OvertimeRate.Text)) / 60

3 个答案:

答案 0 :(得分:3)

Dim i As Integer
Integer.TryParse(value, i)
Console.WriteLine("Integer:", i)

答案 1 :(得分:0)

要将包含数值的字符串转换为实际数字类型(例如int),您需要使用

Integer.Parse(someString)

答案 2 :(得分:0)

也许这样的事情会起作用:

Dim Result as Integer = TimeSpan.Parse(Overtime.Text).TotalMinutes
OvertimeAmount.Text = ((result * Val(OvertimeRate.Text)) / 60).ToString

这假设您正在验证加班中的文本。如果没有,您可以使用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