Joel
Joel

Reputation: 13

CSV in visual Basic

I am trying to seperate the text box list I have using csv. I am saving it to excel and the titles that I have go into their individual cell, but the text boxes go into one. I want them to be in their seperate cell also.

Also, how can I add new information without overwriting the previous info saved?

Thanks

Dim csvFile As String = My.Application.Info.DirectoryPath & "\HoseData.csv"

Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, False)

outFile.WriteLine("job number, sales order number, date")

outFile.WriteLine(TextBox1.Tex & TextBox2.Text & DateTimePicker1.Text)

outFile.Close()

Console.WriteLine(My.Computer.FileSystem.ReadAllText(csvFile))

Upvotes: 0

Views: 573

Answers (1)

Tony Hinkle
Tony Hinkle

Reputation: 4742

You need to add commas in your output:

outFile.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & DateTimePicker1.Text)

Per the additional requirement of quotes around the DateTimePicker data that was fleshed out in the comments below:

outFile.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & """" & DateTimePicker1.Text & """")

To append instead of overwrite, as Plutonix mentioned above, use

OpenTextFileWriter(csvFile, True)

Upvotes: 1

Related Questions