为什么我的布尔值没有设置为真?

问题描述 投票:0回答:0

我的问题是当

YearFolder2Bool = true
, 代码后面有一个简单的 if 语句取决于它是否为真才能运行,但是当它should 变为真时,它基本上不会,如果正在读取的 csv 有超过一年的数据,它会创建那年数据的新文件夹。

我尝试删除

YearFolder2Bool
并将其替换为正在创建的文件夹(后面的 if 语句中发生的部分内容),并检查它是否存在而不是 bool,但这没有用,子字符串正在读取正确的位置和位数,我敢肯定,我已经一遍又一遍地阅读它,试图找出我的逻辑中的缺陷,所以我认为它需要真正的编码人员的眼睛才能看出问题所在。任何人都可以帮忙吗?代码如下:

Dim Line1Year As String
Dim Year2Number As String
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(CSVLogPath)
    MyReader.TextFieldType = FileIO.FieldType.Delimited
    MyReader.SetDelimiters(" ")
    Dim CurrentRow As String()
    'dims

    Dim LineCounter As String = System.IO.File.ReadAllLines(CSVLogPath)(1) ' getting first line
    Line1Year = LineCounter.Substring(6, 4) 'getting year from line
    Year2Number = Line1Year + 1


    While Not MyReader.EndOfData
        Try
            CurrentRow = MyReader.ReadFields() ' reading all lines 1 by 1
            Dim CurrentField As String
            MyReader.ReadFields()
            For Each CurrentField In CurrentRow
                Dim Year1Check = CurrentField.IndexOf("/" & Line1Year) ' checking all lines for same year
                If Year1Check = -1 And CurrentField.Substring(6, 4) = Year2Number Then
                    YearFolder2Bool = True ' if year 1 not found, year 2 number is saved and  year2bool is true
                End If
                If Year1Check = -1 And CurrentField.Substring(6, 4) <> Year2Number Then
                    If CurrentField <> ("DATE   TIME    DIRECTION   SPEED") Then
                        MsgBox("More than 2 years of data have been detected, this data cannot be parsed")
                        Exit Sub
                    End If
                End If
            Next
        Catch ex As Microsoft.VisualBasic.
      FileIO.MalformedLineException
        End Try
    End While
End Using
vb.net winforms
© www.soinside.com 2019 - 2024. All rights reserved.