Reading CSV file some missing columns

后端 未结 3 905
没有蜡笔的小新
没有蜡笔的小新 2021-01-11 12:45

I am trying to read in a CSV file into my VB.net application using the following code:

While Not EOF(1)
    Input(1, dummy)
    Input(1, phone_number)
    Inp         


        
3条回答
  •  情歌与酒
    2021-01-11 12:59

    By using the following Function, you can evaluate the file content line by line and take the appropriate action.

    Imports System.IO    
    Private Sub ParseCSVFile(psFile As String)
        Dim sArray() As String
        Dim Customer_Name As String = String.Empty
        Dim Phone_Number As String = String.Empty
        Dim Username As String = String.Empty
        Dim Product As String = String.Empty
        Dim Wholesale_Cost As String = String.Empty
        Dim Sales_Price As String = String.Empty
        Dim Gross_Profit As String = String.Empty
        Dim Customer_Reference As String = String.Empty
    
        Try
            Using objStreamReader As StreamReader = New StreamReader(psFile) 'should be full path
                Dim sLine As String = String.Empty
                Do
                    sLine = objStreamReader.ReadLine()
                    If sLine <> Nothing Then
                        sArray = Split(sLine, ",")
                        Customer_Name = sArray(0)
                        Phone_Number = sArray(1)
                        Username = sArray(2)
                        Product = sArray(3)
                        Wholesale_Cost = sArray(4)
                        Sales_Price = sArray(5)
                        Gross_Profit = sArray(6)
                        Customer_Reference = sArray(7)
                        Debug.Print(Customer_Name & "," & Phone_Number & "," & Username & "," & Product & "," & Wholesale_Cost & "," & Sales_Price & "," & Gross_Profit & "," & Customer_Reference)
                    End If
                Loop Until sLine Is Nothing
            End Using
        Catch
            'log error
        End Try
    End Sub
    

提交回复
热议问题