Last post Jan 29, 2020 02:16 AM by Yang Shen
Jan 27, 2020 11:49 PM|Rekos|LINK
Hello! I'm trying to make a program in VB to take the first 25 rows of a little over 150 CSV files and copy them into one larger dataset. Each dataset has a top row with notes and a header row that must be skipped, so the data I'd like to copy is on rows
3-28. I'm able to select the files and read them, but I can't figure out how to actually select the rows I want and opy them over. Here's what I have so far:
For Each file In files
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(file)
MyReader.TextFieldType = FileIO.FieldType.Delimited
Dim currentRow As String()
While Not MyReader.EndOfData
currentRow = MyReader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
Dim x As Integer = MyReader.LineNumber
Select Case x
Case x <= 3
Case x > 28
Case x >= 4
strLine &= currentField & ","
linesToAdd(x - 1) = strLine
MsgBox(linesToAdd(x)) 'checking if it entered right, returns infinite blank message boxes now
Sorry if it's sloppy, I haven't coded anything in a while and this has been pretty daunting. Any help is greatly appreciated!
Jan 29, 2020 02:16 AM|Yang Shen|LINK
What's the program type? A Windows Form application?
Each dataset has a top row with notes and a header row that must be skipped, so the data I'd like to copy is on rows 3-28.
Do you mean you want to copy 3rd-27th rows(3-28 should be 26 rows) of your CSV file to a dataset?
In this case, you will need to use the Skip() to the first two rows and then select 25 rows out, you can refer to
this answer which is coded with C# but can be converted easily.