[RESOLVED] Creating Comma Separated File
This is my first 'serious' VB2008 project. Attempting to write a comma separated file. vis:
Code:
Dim JobC As Integer
Dim iWrite As New StreamWriter("C:\LogTest.txt", False)
Dim OutputLine As String
For JobC = 1 To HelpDesk.Count
jobs(JobC - 1) = New Jobs(HelpDesk(JobC), TypeA(JobC), Specialist(JobC), Comments(JobC), Summary(JobC), Description(JobC))
OutputLine = HelpDesk(JobC) + "," + TypeA(JobC) + "," + Specialist(JobC) + "," + Comments(JobC) + "," + Summary(JobC) + "," + Description(JobC)
iWrite.WriteLine(OutputLine)
Next
iWrite.Close()
dgv1.DataSource = jobs
Is there a better method for outputing the data, rather than having to concatinate all the elements into a string and then writing it?
In the 'good old VB6' days a Print statement followed by each value and a separator would do the trick. I can't seem to find the appropriate override for the WriteLine method.
Re: Creating Comma Separated File
I'm curious as to why you have all those separate arrays in the first place if you actually do have a Jobs class that represents a single job. By the way, if it represents a single job then it should be named Job, not Jobs.
Regardless, I would tend to replace this:
vb.net Code:
OutputLine = HelpDesk(JobC) + "," + TypeA(JobC) + "," + Specialist(JobC) + "," + Comments(JobC) + "," + Summary(JobC) + "," + Description(JobC)
iWrite.WriteLine(OutputLine)
with this:
vb.net Code:
iWrite.WriteLine(String.Join(",", HelpDesk(JobC), TypeA(JobC), Specialist(JobC), Comments(JobC), Summary(JobC), Description(JobC)))
Re: Creating Comma Separated File
there's an overload of writeline that takes a format + parameters:
vb Code:
iWrite.WriteLine("{0},{1},{2},{3},{4},{5}", HelpDesk(JobC), TypeA(JobC), Specialist(JobC), Comments(JobC), Summary(JobC), Description(JobC))
Re: Creating Comma Separated File
p.s. greetings from danbury...
Re: Creating Comma Separated File
Thanks guys. I knew there'd be a simple answer.
@JM - The 'Arrays' in question are actually Collections and the method I'm using was taken from an example I found for populating a DataGridView. (I'm using a DGV rather than Listview as I wanted multiple lines in the cells which didn't seem to be too easy to do with a ListView)
@Paul: Thanks, Greetings recpricated