我是一名正在研究Visual Basic
的学生,我将以下代码完全复制到了本书所说的内容中:
intNumberofBikes = Convert.ToInt32(strNumberofBikes)
我收到以下错误: VbScreenShot
任何帮助将不胜感激,我无法找出代码有什么问题。
答案 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