Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

Copying specific rows from a set of CSV files

$
0
0

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
                MyReader.SetDelimiters(",")

                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
                        End Select
                    Next
                End While
            End Using
        Next

Sorry if it's sloppy, I haven't coded anything in a while and this has been pretty daunting. Any help is greatly appreciated!


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>