Current code writes out a .txt file. What changes are required to make this a .cvs file?

Public Sub WriteData()
        Try

            JobLogger.Write("STARTING WriteData() ")
            Dim dr As DataRow = Nothing
            Dim int_TotalHDCount As New Integer
            Dim int_TotalnonHDCount As New Integer
            Dim int_TotalRowCount As New Integer

            For Each dr In dt_filedata.Rows
                'Count Total Rows
                int_TotalRowCount = int_TotalRowCount + 1

                If dr.Item("ppd_ClassOfSale").ToString.Trim = "HD" AndAlso
                    dr.Item("ST_Route") <> "" Then

                    'counts the HD record's, Non-HD record's, and Counts total rows
                    int_TotalHDCount = int_TotalHDCount + 1
                    'for fixed length file structure
                    'Pad adds sets specific length to column, with specific character in this case " "
                    sb_outline.Append(dr("ST_Route").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_SellingProduct").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_DeliveryProduct").ToString.Trim.PadRight(10, " "))
                    sb_outline.Append(dr("ST_PublishDate").ToString.Trim.PadRight(10, " "))
                    sb_outline.Append(dr("ST_Quantity").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_PreprintScheduleID").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_CustomerName").ToString.Trim.PadRight(25, " "))
                    'sb_outline.Append(dr("ST_VersionDescription").ToString.Trim.PadRight(8, " "))
                    'sb_outline.Append(dr("ST_AdLine").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_PaperSection").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_CarrierBonusCode").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_CarrierBonusAMT").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_PreprintType").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_Weight").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_PackageName").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_PackageSequence").ToString.Trim.PadRight(10, " "))
                    sb_outline.Append(dr("ST_ClassOfSale").ToString.Trim.PadRight(15, " "))
                    'sb_outline.Append(dr("ST_AdZone").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_Pages").ToString.Trim.PadRight(10, " "))

                Else : int_TotalnonHDCount = int_TotalnonHDCount + 1
                End If

                sw_Output_writer.WriteLine(sb_outline)
                sw_Output_writer.Flush()
                sb_outline.Clear()

            Next
            For Each dr In dt_filedata.Rows
                If dr.Item("ppd_ClassOfSale").ToString.Trim = "SC" AndAlso
                                      dr.Item("ST_Route") <> "" Then


                    int_TotalHDCount = int_TotalHDCount + 1
                    'for fixed length file structure
                    'Pad adds sets specific length to column, with specific character in this case " "
                    sb_outline.Append(dr("ST_Route").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_SellingProduct").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_DeliveryProduct").ToString.Trim.PadRight(10, " "))
                    sb_outline.Append(dr("ST_PublishDate").ToString.Trim.PadRight(10, " "))
                    sb_outline.Append(dr("ST_Quantity").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_PreprintScheduleID").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_CustomerName").ToString.Trim.PadRight(25, " "))
                    'sb_outline.Append(dr("ST_VersionDescription").ToString.Trim.PadRight(8, " "))
                    'sb_outline.Append(dr("ST_AdLine").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_PaperSection").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_CarrierBonusCode").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_CarrierBonusAMT").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_PreprintType").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_Weight").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_PackageName").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_PackageSequence").ToString.Trim.PadRight(10, " "))
                    sb_outline.Append(dr("ST_ClassOfSale").ToString.Trim.PadRight(15, " "))
                    'sb_outline.Append(dr("ST_AdZone").ToString.Trim.PadRight(10, " "))
                    'sb_outline.Append(dr("ST_Pages").ToString.Trim.PadRight(10, " "))



                Else : int_TotalnonHDCount = int_TotalnonHDCount + 1
                End If

                sw_Output_writer.WriteLine(sb_outline)
                sw_Output_writer.Flush()
                sb_outline.Clear()

            Next

        End Try
    End Sub
Jeremy GohmanNetwork EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

F IgorDeveloperCommented:
In some other place the object "sw_Output_writer" is created and probably assigning the target filename for writing.
Search in your code for this object name, search for the name of the file, or the extension ".txt". If you find it, change ".txt" to ".csv" in the filename.
0
Prakash SamariyaIT ProfessionalCommented:
You do not need to fixed length file structure for .CSV;

Just replace the extension from ".TXT" into ".CSV" and
Replace all line which contains ".PadRight()" and Add ";" (semicolon) as the column separator like below
OLD LINE:
sb_outline.Append(dr("ST_Route").ToString.Trim.PadRight(10, " "))
NEW LINE:
sb_outline.Append(dr("ST_Route").ToString.Trim+";")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeremy GohmanNetwork EngineerAuthor Commented:
what exactly does +";" do?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.