我在程序中遇到特定代码行的问题。代码 _intValue(intcount)= Convert.ToInt32(objReader.ReadLine()) 的行给我一个错误,说明"输入字符串不在格式正确"我不知道为什么。任何人都可以帮我解决这个问题吗?这是代码:
Option Strict On
Public Class frmClassicCarShow
Public Shared _intSIZE As Integer = 10
Public Shared _strCarandyear(_intSIZE) As String
Private _intValue(_intSIZE) As Integer
Private Sub frmClassicCarShow_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs) Handles btnCalculate.Click
Dim objReader As IO.StreamReader
Dim intcount As Integer = 0
Dim CarModel As String = ""
Dim intCar As Integer = 0
Dim intValue As Integer
Dim _intPrice As Integer
'verify the file exist
If IO.File.Exists("C:\cars.txt") Then
objReader = IO.File.OpenText("C:\cars.txt")
' read file line by line
Do While objReader.Peek <> -1
_strCarandyear(intcount) = objReader.ReadLine()
_intValue(intcount) = Convert.ToInt32(objReader.ReadLine())
intcount += 1
Loop
objReader.Close()
'place word into array
For Each CarModel In (_strCarandyear)
lstCars.Items.Add(CarModel)
Next
'sums up the number of cars
For Each _strName In _strCarandyear
intCar += 1
Next
lblTotalCars.Text = intCar.ToString
For Each _intPrice In _intValue
intValue += _intPrice
Next
lblTotalValue.Text = intValue.ToString
btnCalculate.Enabled = False
lblTotalCars.Visible = True
lblTotalValue.Visible = True
Else
MsgBox("The file ""cars.txt"" is not available. Put the file ""cars.txt"" located in the zip folder of this program onto your local disk drive and then restart the program", , "Error")
Close()
End If
End Sub
End Class