我正在使用 .NET Framework 1.0 ,我尝试将String转换为int但引发错误 输入字符串格式不正确
看看我的代码
Dim Total As Integer
Total = (Convert.ToInt32(Me.lblOldQty.Text)) - (Convert.ToInt32(Me.txtQty.Text))
Dim Value As String = Me.lblOldQty.Text + " - " + Me.txtQty.Text + " = " + Convert.ToString(Total)
Me.lblNewValue.Text = Value
我已尝试使用 CInt和Integer.Parse 但结果相同。
任何帮助将不胜感激
答案 0 :(得分:0)
试试这个:
Dim Total As Integer
Total = Integer.Parse(lblOldQty.Text) - Integer.Parse(txtQty.Text)
Dim Value As String = lblOldQty.Text + " - " + txtQty.Text + " = " + Convert.ToString(Total)
lblNewValue.Text = Value
执行时使用断点并检查值是否正确传递到lblOldQty.Text
和txtQty.Text
答案 1 :(得分:0)
Dim OldQty, Qty, Total As Integer
If Int32.TryParse(Me.lblOldQty.Text, OldQty) AndAlso Int32.TryParse(Me.txtQty.Text, Qty) Then
Total = OldQty + Qty
End If