Solved

Problem with  StreamWriter not writting  the  whole line

Posted on 2013-05-16
5
592 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
  • 3
  • 2
5 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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