Vb.net 输入字符串格式不正确错误消息:Visual basic

Vb.net 输入字符串格式不正确错误消息:Visual basic,vb.net,Vb.net,我的程序中有一行代码有问题。代码为\u intValue(intcount)=Convert.ToInt32(objReader.ReadLine())的行给了我一个错误,显示“输入字符串格式不正确”,我不知道为什么。有人能帮我解决这个问题吗?代码如下: Option Strict On Public Class frmClassicCarShow Public Shared _intSIZE As Integer = 10 Public Shared _strCarandyea

我的程序中有一行代码有问题。代码为\u 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
选项严格打开
公共类frmClassicCarShow
公共共享_intSIZE为整数=10
公共共享_strcandYear(_intSIZE)作为字符串
Private _intValue(_intSIZE)作为整数
私有子frmClassicCarShow_Load(发送方作为System.Object,e作为System.EventArgs)处理MyBase.Load
端接头
私有子btnCalculate\u单击(发送方作为System.Object,e作为System.EventArgs)处理btnCalculate。单击
Dim objReader作为IO.StreamReader
Dim intcount作为整数=0
Dim CarModel As String=“”
Dim intCar作为整数=0
将整数值设置为整数
Dim\u intPrice作为整数
'验证文件是否存在
如果IO.File.Exists(“C:\cars.txt”),则
objReader=IO.File.OpenText(“C:\cars.txt”)
'逐行读取文件
当objReader.Peek-1
_strCarandyear(intcount)=objReader.ReadLine()
_intValue(intcount)=Convert.ToInt32(objReader.ReadLine())
整数计数+=1
环
objReader.Close()
'将单词放入数组
对于(_strcarndyear)中的每个CarModel
lstCars.Items.Add(CarModel)
下一个
”他总结了汽车的数量
对于每一年中的每个名称
intCar+=1
下一个
lblTotalCars.Text=intCar.ToString
对于每个_intpricein _intValue
intValue+=\u intPrice
下一个
lblTotalValue.Text=intValue.ToString
btnCalculate.Enabled=False
lblTotalCars.Visible=True
lblTotalValue.Visible=True
其他的
MsgBox(“文件”“cars.txt”“不可用。请将此程序zip文件夹中的文件”“cars.txt”“放入本地磁盘驱动器,然后重新启动程序”“错误”)
关闭()
如果结束
端接头
末级

objReader.ReadLine()
正在返回无法转换为整数的字符串(即其中包含非数字字符)。非常感谢!!!昨晚我编辑了原始的“cars.txt”文件,当时我有不同的代码,所以它实际上是在读取空格。我把它改回原来的“carts.txt”文件,这样我就可以读取数字了。现在完全有道理了。非常感谢!如果没有你的暗示,我要花很长时间才能找出我犯的错误。这个程序现在运行得很好