1

我有一个 If 和一个 nested-If ,它拒绝列值大于 0 的行。nested-If 应该检查双精度值并添加我需要的重复值,但事实并非如此。我不确定我在这里缺少什么。

 Dim rowValue As String
    Dim cellValue As String()

    If System.IO.File.Exists("shortlist.csv") Then

        Using streamReader As System.IO.StreamReader = New StreamReader("shortlist.csv")
            'Defines columns
            rowValue = streamReader.ReadLine()
            cellValue = rowValue.Split(",")
            With dgv.Columns
                .Add(cellValue(0).ToString, cellValue(0).ToString)
                .Add(cellValue(3).ToString, cellValue(3).ToString)
                .Add(cellValue(5).ToString, cellValue(5).ToString)
                .Add(cellValue(6).ToString, cellValue(6).ToString)
                .Add(cellValue(8).ToString, cellValue(8).ToString)
            End With

            ' Reading content
            While streamReader.Peek() <> -1
                Dim cnt As Integer = 0
                rowValue = streamReader.ReadLine()
                cellValue = rowValue.Split(",")
                If (cellValue(6) > 0) Then
                    'comparing works. need to tinnker with loop.
                    If (cellValue(0).ToString <> dgv.Rows(cnt).Cells("Phone Number").Value) Then
                        dgv.Rows.Add(cellValue(0).ToString, cellValue(3).ToString, cellValue(5).ToString, cellValue(6).ToString, cellValue(8).ToString)
                    Else
                        dgv.Rows(cnt).Cells(3).Value = (cellValue(6) + Integer.Parse(dgv.Rows(cnt).Cells(3).Value))
                        dgv.Rows(cnt).Cells(4).Value = (cellValue(8) + Integer.Parse(dgv.Rows(cnt).Cells(4).Value))
                        cnt += 1
                    End If

                End If
            End While
        End Using
    Else
        MsgBox("No File is Selected")
    End If

我正在使用的 .CSV 文件有几列,第一列是电话号码。当我阅读每一行电话号码并遇到重复的电话号码时,我想将两列中的值添加到它们唯一的行中。

4

0 回答 0