未处理的格式

时间:2017-02-19 17:58:08

标签: vb.net exception

我是一名正在研究Visual Basic的学生,我将以下代码完全复制到了本书所说的内容中:

 intNumberofBikes = Convert.ToInt32(strNumberofBikes)

我收到以下错误: VbScreenShot

任何帮助将不胜感激,我无法找出代码有什么问题。

1 个答案:

答案 0 :(得分:1)

错误是因为您在文本字段中有一个非数字字符...请尝试以下操作...

 Dim intBikes As Integer = 0 
 Integer.TryParse(strNumberofBikes, intBikes)

如果错误成功解析文本字段,则错误将消失,intBikes将成为计数。

整件事情结束了......

 Dim intBikes As Integer
 Dim decTotalCost As Decimal 
 If Integer.TryParse(txtNumberOfBikes.Text, intBikes) Then
    decTotalCost = intBikes * _cdecPricePerBike
    lblTotalCost.Text = decTotalCost.ToString("C")
 End If