Hello Guys,
I have a website order export as a raw csv file with the various fields one after the other, with a separate line for each order. I want to read in that file, assigning each field to a variable so I can analyse those variables and then do some manipulations, before finally exporting to a new csv file to have it in an appropriate format for import to an accounts package called Quickbooks.
I'm right at the beginning of this, so at present I just want to be able to read in the csv file to the variables for writing straight back out into a new file - as a first step.
I searched the posts on 'csv' and found some pointers for starters, but I'm having trouble using the 'Input' command to read in the csv file to the variables, since the source file varies in the number of fields depending on whether the product in question has some additional product options fields passed over also.
I thought maybe I could say add a few extra holding variables and just read in, with the Input command just reading in blank values at the end of the line, but it seems to jump down and start reading in the fields of the next line.
Here is the code I've used forthe first simple test - its reading in 50 fields (46 fields from the first line, but then the first 4 fields of the second line also).
===============================================
Private Sub Command1_Click()
Open "D:\orders.csv" For Input As #1
Input #1, Field1, Field1, Field2, ... , Field50
Close #1
Open "D:\QB_Import.csv" For Output As #1
Write #1, Field1, Field2, ... , Field50
Close #1
End Sub
===============================================
Is there a way to make that work or can I use some other command or way of doing this. Can I use some sort of end of line test and count along the fields of a row and copy them into an array for storage, using that counter as the array pointer to extract the correct number of items back from that array?
I'm a newbie to VB, so I don't really know the command names to read more about. Any help with an example snippet of code or pointers on the appropriate commands I should be looking at, would be greatly appreciated.
Thanks for your help.
Philip.
I have a website order export as a raw csv file with the various fields one after the other, with a separate line for each order. I want to read in that file, assigning each field to a variable so I can analyse those variables and then do some manipulations, before finally exporting to a new csv file to have it in an appropriate format for import to an accounts package called Quickbooks.
I'm right at the beginning of this, so at present I just want to be able to read in the csv file to the variables for writing straight back out into a new file - as a first step.
I searched the posts on 'csv' and found some pointers for starters, but I'm having trouble using the 'Input' command to read in the csv file to the variables, since the source file varies in the number of fields depending on whether the product in question has some additional product options fields passed over also.
I thought maybe I could say add a few extra holding variables and just read in, with the Input command just reading in blank values at the end of the line, but it seems to jump down and start reading in the fields of the next line.
Here is the code I've used forthe first simple test - its reading in 50 fields (46 fields from the first line, but then the first 4 fields of the second line also).
===============================================
Private Sub Command1_Click()
Open "D:\orders.csv" For Input As #1
Input #1, Field1, Field1, Field2, ... , Field50
Close #1
Open "D:\QB_Import.csv" For Output As #1
Write #1, Field1, Field2, ... , Field50
Close #1
End Sub
===============================================
Is there a way to make that work or can I use some other command or way of doing this. Can I use some sort of end of line test and count along the fields of a row and copy them into an array for storage, using that counter as the array pointer to extract the correct number of items back from that array?
I'm a newbie to VB, so I don't really know the command names to read more about. Any help with an example snippet of code or pointers on the appropriate commands I should be looking at, would be greatly appreciated.
Thanks for your help.
Philip.