Solved

Problem with  StreamWriter not writting  the  whole line

Posted on 2013-05-16
5
590 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now