Results 1 to 3 of 3

Thread: VB2010: Dealing with CSV files

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    17

    VB2010: Dealing with CSV files

    Hi,

    I have a two column CSV file embedded in a VB2010 project. I'd like the user to enter some text into a text box which matches with column A of the CSV file - the code should then return the corresponding text in Column B of the cvs file.

    I'm a little confused on the best method of dealing with the CSV file..an array? convert to some sort of DB? etc etc.

    The only proviso is that as the CSV files change frequently, I need a method that can act 'on the fly' rather than laborious first time job.

    Can anyone suggest a good method with code example please?

    Thanks
    David

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: VB2010: Dealing with CSV files

    You could use the TextFieldParser class, designed for this sort of thing. Once you read in the file, save the filedate/size into a variable and put it into a datatable. Each time you need to process the data, check if the filedate/size has changed, if so reimport, or use the existing datatable.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    311

    Re: VB2010: Dealing with CSV files

    If there are only the two columns and you want the data in one to point to the data in the other column, then I'd think a Dictionary(Of T, T) would be the best data storage for what you need. In a Dictionary, the items are set up as Key-Value pairs that you can easily get the data you need using the Key to retrieve the associated value:
    Code:
    myValue = myDictionary(myKey)

Tags for this Thread

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