IDE认为我需要关闭一个循环,但它看起来很好

时间:2014-12-29 15:26:58

标签: vb.net visual-studio-2010 for-loop

IDE说

的下一步
for i

正好在"循环文件夹注释中缺失。

这是我的代码。

Dim strVal As String

    'Loop through Folders
    For i As Integer = 0 To lbFolder.Items.Count - 1
        Dim iText As String = CStr(lbFolder.Items(i))
        Dim partPath As String = lblPath.Text + "\" + iText
        Dim pathNum As String = partPath + "\1900\"
        Dim directory As New DirectoryInfo(pathNum)
        Dim fileArr As FileInfo() = directory.GetFiles() ' Get a reference to each file in that directory.
        ' Display the names of the files.
        Dim xItem As FileInfo
        'loop through files

        For Each xItem In fileArr ' add to listbox
            lblFname.Text = xItem.ToString
            strVal = pathNum & xItem.ToString
            lbFiles.Items.Add(strVal)
        Next

        For j = 0 To lbFiles.Items.Count - 1 'read through files listbox
            Dim FileID, Sequence, Time, Lat, Longitude, Average, Channel As String
            'declaration of filestream to open file
            Dim sr As StreamReader
            'filestream object to open and read file
            Dim fs As FileStream
            Try
                'clearing listbox data toavoid confusion
                ListView1.Items.Clear()
                fs = New FileStream((lbFiles.Items.Item(j)), FileMode.OpenOrCreate)
                'stream reader object to read streamed input
                sr = New StreamReader(fs)
                Dim itm As Object
                'reading line by line
                itm = sr.ReadLine
                While Not itm = Nothing
                    Dim split As String() = itm.Split(New [Char]() {","})
                    FileID = split(0)
                    Sequence = split(1)
                    Time = split(2)
                    Lat = split(3)
                    Longitude = split(4)
                    Average = split(5)
                    Channel = split(6)
                    With ListView1
                        .Items.Add(FileID)
                        .Items(ListView1.Items.Count - 1).SubItems.Add(Sequence)
                        .Items(ListView1.Items.Count - 1).SubItems.Add(Time)
                        .Items(ListView1.Items.Count - 1).SubItems.Add(Lat)
                        .Items(ListView1.Items.Count - 1).SubItems.Add(Longitude)
                        .Items(ListView1.Items.Count - 1).SubItems.Add(Average)
                        .Items(ListView1.Items.Count - 1).SubItems.Add(Channel)
                    End With
                    itm = sr.ReadLine
                End While
                'close stream reader and filestrema object
                sr.Close()
                fs.Close()
            Catch ex As System.Exception
                System.Windows.Forms.MessageBox.Show(ex.Message, "Load Tool Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        Next j
        lbFiles.Items.Clear()
    Next i
End Sub

我正在使用visual studio,当我点击for i时它会显示下一个结束但是当我运行时我得到一个错误。

我错过了什么?

2 个答案:

答案 0 :(得分:0)

   Add **xItem** after the Next

   For Each xItem In fileArr ' add to listbox
        lblFname.Text = xItem.ToString
        strVal = pathNum & xItem.ToString
        lbFiles.Items.Add(strVal)
    Next xItem

答案 1 :(得分:-1)

重新启动IDE,一切运行都没有错误。

感谢所有回复的人