为什么无法获得总行数?

时间:2019-12-13 05:45:10

标签: vb6

我正在使用VB6,我想通过两次使用Do Unitel文件结尾两次来首先获取总行作为下一步的参考。

先做

从文件中获取总行

第二秒

显示循环值,但系统跳过秒操作

请参阅我的代码

   Dim FileNumber As Integer = FreeFile()
    Dim FirstLine As Boolean = True
    Dim rownum As Int32 = 0
    Dim Totalrow As Int32 = 0
    Dim MinY As Double = 999999
    Dim MaxY As Double = -999999
    Dim DiffY As Double = 0
    Dim currentval As Double = 0
    Try
        FileOpen(FileNumber, XMFileName, OpenMode.Input)
        Do Until EOF(FileNumber)
            Dim Text As String = LineInput(FileNumber)
            Dim _val = Text.Split(vbTab)
            Totalrow += 1
        Loop

        Do Until EOF(FileNumber)
            Dim Text As String = LineInput(FileNumber)
            Dim _val = Text.Split(vbTab)
            rownum += 1
            If FirstLine Then
                For i As Integer = 0 To Text.Length - 1
                Next
                FirstLine = False
            Else
                If rownum >= 364 And rownum <= 695 Then
                    currentval = CDbl(_val(1).ToString())
                    If MinY > currentval Then
                        MinY = currentval
                    End If
                End If

                If rownum >= 696 And rownum <= Totalrow - 4 Then
                    currentval = CDbl(_val(1).ToString())
                    If MaxY < currentval Then
                        MaxY = currentval
                    End If
                End If
            End If
        Loop

        If MinY = 999999 Or MaxY = -999999 Then
            MessageBox.Show("Program can't read QC file at row" & rownum.ToString() & ", Please manual check the data.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
            'Else
            DiffY = MaxY - MinY
            'MessageBox.Show(Math.Round(DiffY, 5))
            Dim lvitem As ListViewItem
            lvitem = Me.uiListView.Items.Add(MinY)
            lvitem.SubItems.Add(MaxY)
            lvitem.SubItems.Add(Math.Round(DiffY, 5))
            For Each lvi As ListViewItem In Me.uiListView.Items
                lvi.UseItemStyleForSubItems = False
                lvi.SubItems(2).ForeColor = Color.Yellow
                lvi.SubItems(2).Font = New Font("Microsoft Sans Serif", 10, FontStyle.Bold)
            Next
        End If
    Catch ex As Exception
        MessageBox.Show("QC measurement error at row :  " & rownum.ToString() & ". QC file less than condition. It must be more than 193 rows." & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Exit Sub
    Finally
        FileClose(FileNumber)
    End Try

还有其他方法可以获取总行以供参考吗?

非常感谢朋友。

1 个答案:

答案 0 :(得分:1)

第二个循环的eof条件在开始时为真,因为它也是第一个循环的结束条件,所以完全不能执行第二个循环。

在两个循环之间关闭并重新打开文件,以解决该问题。