[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 604
  • Last Modified:

Problem with StreamWriter not writting the whole line

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
cin_champ
Asked:
cin_champ
  • 3
  • 2
1 Solution
 
Arthur_WoodCommented:
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
 
cin_champAuthor Commented:
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
 
Arthur_WoodCommented:
OUTPUT = myTESTDATE.TOSTRING + "," + myOPERATOR.tostring + "," + myEVNAME

you concatenate the ACTUAL values, with the comma separators

AW
0
 
cin_champAuthor Commented:
Thank You

this worked for me (no first +:


 OUTPUT = col1" + "," +"col2" + "," + "col3" + "," + "col4" + "," + "col5
0
 
Arthur_WoodCommented:
Glad to be of assistance

AW
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now