VB 2010 Express:用于下一个错误

时间:2013-10-18 07:28:24

标签: visual-studio-2010

所以我刚刚开始学习VB,我想我误解了我一直关注的教程,因为我无法弄清楚我在做错了什么。也许我在想它?

问题在于以下行,“IndexOutOfRangeException”

If aryTextLine(i) = "True" Then

在此先感谢您的帮助。

Public Function FindTabPos(ByVal low As Integer, ByVal high As Integer)
    If opCounter >= 3 Then

        Dim TextLine As String

        Dim TrueCount As Integer
        TrueCount = 0

        TextLine = ""
        Dim aryTextLine() As String
        If System.IO.File.Exists(configLoc) = True Then

            Dim objReader As New System.IO.StreamReader(configLoc)
            Do While objReader.Peek() <> -1

                TextLine = TextLine & objReader.ReadLine() & vbNewLine

            Loop

            aryTextLine = TextLine.Split(",")

            For i = 0 To UBound(aryTextLine)
                MsgBox(aryTextLine(i))
            Next i

            For i = low To high
                If aryTextLine(i) = "True" Then
                    TrueCount = TrueCount + 1
                End If
            Next i
        End If
        Return TrueCount
    Else
        Return False
    End If
End Function

编辑:我发现了我的问题。它正在阅读的文件是一个列表。由于我误解了“TextLine = TextLine&amp; objReader.ReadLine()&amp; vbNewLine”是如何工作的,我试图用。逗号(。)来逗号而不是换行。以下是本网站上的另一个问题,修复了它。

aryTextLine = TextLine.Split(New String() {Environment.NewLine}, StringSplitOptions.None)

0 个答案:

没有答案
相关问题