asked on
Private Function ParseCSVs() As Boolean
Dim LocalFilePath As String = String.Empty
For Each aCSV As xCSV In _CSVs
LocalFilePath = My.Settings.Item("GRFiles") & "DailyOrders\" & aCSV.CSVFileName
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(LocalFilePath)
MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
MyReader.Delimiters = New String() {","} '{vbTab}
Dim currentRow As String()
'Loop through all of the fields in the file.
'If any lines are corrupt, report an error and continue parsing.
Dim OrderRequest As New cCSVOrderRequest
OrderRequest.Items = New List(Of cCSVProductItem)
Dim Product As ProductClass = Nothing
Dim Item As cCSVProductItem = Nothing
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
' Include code here to handle the row.
Dim fields As String() = MyReader.ReadFields()
Item = New cCSVProductItem()
Item.OrderItemNumber = fields(0)
Item.PartNumber = fields(2)
Item.Description = fields(3)
Item.Quantity = fields(4)
Item.ShipTitle = fields(17)
Item.ShipToName = fields(18)
Item.ShipAddress1 = fields(19)
Item.ShipAddress2 = fields(20)
Item.ShipAddress3 = fields(21)
Item.ShipAddress4 = fields(22)
If fields(23).Contains("GB") Then
Item.ShipCountry = "238"
Else
Item.ShipCountry = ""
'CommonFunctions.SendErrorEmail("")
End If
Item.ShipPostCode = fields(24)
Item.PhoneNumber = fields(28)
OrderRequest.Items.Add(Item)
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
'CommonFunctions.SendErrorEmail("")
Return False
End Try
End While
aCSV.OrderRequest = OrderRequest
End Using
Next
Return True
End Function
Untitled.png
ASKER
ASKER
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
TRUSTED BY
Item.OrderItemNumber = fields(0)
This is where you are reading in both lines in the file in the first pass. Modify the code to read once per pass.
Open in new window