Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem with  StreamWriter not writting  the  whole line

Posted on 2013-05-16
5
Medium Priority
?
598 Views
Last Modified: 2013-05-16
I'm using a string reader to go through a CSV file parsing it and rebuilding a new extract. HAving problems with wtriting to csv  (Using excel 2003, VB 2010.)
 Dim sWriter As StreamWriter = New StreamWriter("c:\temp\test.csv")
 Dim filePath As String = "c:\temp\test.csv"

 Using dReader As New StreamReader(filePath)
            Dim line As String
            Dim myFlag As Boolean
            sWriter.Write("col1","col2","col3","col1","col2","col3")
            sWriter.WriteLine()  
 ' have to use this extra  sWriter.WriteLine()    or no line break  the date filed  tags along on first row and just  sWriter.WriteLine()    does not give a line breck.


 line = dReader.ReadLine()

items = line.Split(",".ToCharArray())
                           col1= (items(1).ToString)
                            col2 =(myOrdNo.Substring(0, 1) + "0000" + Mid(items(1).ToString, 3, 7))
                            col3 = (myOrdNo.Substring(0, 1) + "0")

sWriter.Write(myTESTDATE, col1, col2, col(3).ToString)   ' I tried tostring no difference....


I get thehearder Row
then only the first  col date value when I inspect the row data before it loads it's there....

I even tried (myTESTDATE, "test","test","test",) same results...
Any ideas anyone?




Does anyone know a better way?
0
Comment
Question by:cin_champ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 2000 total points
ID: 39171961
you need to build the output string EXACTLY as it is to be written to the file - that is, you add the commas yourself:

string output = string.Empty;
output = "col1" + "," +"col2" + "," + "col3" + "," + "col4" + "," + "col5";
sWrite.WriteLine(output);

AW
0
 

Author Comment

by:cin_champ
ID: 39172128
AW,
How do I string it properly if I have values?

 OUTPUT = " & myTESTDATE.TOSTRING &" + "," + "&myOPERATOR.tostring&" + "," + " &myEVNAME&"

this does does not work.... any sugestions on how I pass my values?

Thank You so much!
CJ
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 39172161
OUTPUT = myTESTDATE.TOSTRING + "," + myOPERATOR.tostring + "," + myEVNAME

you concatenate the ACTUAL values, with the comma separators

AW
0
 

Author Closing Comment

by:cin_champ
ID: 39172191
Thank You

this worked for me (no first +:


 OUTPUT = col1" + "," +"col2" + "," + "col3" + "," + "col4" + "," + "col5
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 39172214
Glad to be of assistance

AW
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question