Results 1 to 5 of 5

Thread: [RESOLVED] Creating Comma Separated File

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Resolved [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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:
    1. OutputLine = HelpDesk(JobC) + "," + TypeA(JobC) + "," + Specialist(JobC) + "," + Comments(JobC) + "," + Summary(JobC) + "," + Description(JobC)
    2. iWrite.WriteLine(OutputLine)
    with this:
    vb.net Code:
    1. iWrite.WriteLine(String.Join(",", HelpDesk(JobC), TypeA(JobC), Specialist(JobC), Comments(JobC), Summary(JobC), Description(JobC)))
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Creating Comma Separated File

    there's an overload of writeline that takes a format + parameters:

    vb Code:
    1. iWrite.WriteLine("{0},{1},{2},{3},{4},{5}", HelpDesk(JobC), TypeA(JobC), Specialist(JobC), Comments(JobC), Summary(JobC), Description(JobC))

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Creating Comma Separated File

    p.s. greetings from danbury...

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width