Populate ArrayList from CSV

Discussion in 'Questions (Windows Mobile)' started by linum, Jan 6, 2009.

  1. linum

    linum Active Member Licensed User

    Is it possible to populate an ArrayList from data stored in a csv file? Could somebody please post an example?


    Thank you...
     
  2. Mr_Gee

    Mr_Gee Active Member Licensed User

    Code:
    'load csv
    table1.loadCSV("filename.csv",",",true,true)

    'read line by line
    for i=0 to table1.count -1
    'and add to arraylist, don't forget to fill in columnlist
       al1.add(Table1.Cell(Columname,i))
    Next
    or the below, depending on the data
    Code:
    please note this will not pick up the first item, but this usually has the column names
    fileopen(c1,filename,cRead)
    s = Fileread(c1)
    Do Untill s = EOF
    s = Fileread(c1)
         
    'optional : If NOT(s = "@eof@") Then 
       al1.Add(s)
    Loop
    Fileclose(c1)
     
    Last edited: Jan 6, 2009
  3. Cableguy

    Cableguy Expert Licensed User

    the straight answer is yes...
    But it all deppends on how you are readding the csv..
    are you using the table control to read/load the data to the table or using FileRead?

    PS. Mr_Gee beatted me to the clock...
     
    Last edited: Jan 6, 2009
  4. Cableguy

    Cableguy Expert Licensed User

    Mr_Gee, you need an extra "s=FileRead(c1)" before the "Loop" or the "s" value is never changed...
     
  5. Mr_Gee

    Mr_Gee Active Member Licensed User

    Not completely :)
    updated my post with the s=fileread(c1)
    Not sure how i've missed that, thanks for the pointer
     
  6. linum

    linum Active Member Licensed User

    Wow! I just got a chance to log in and I find nothing but great answers, thank you so much.

    I still don't know how I want to load my data. Is it easier to load it into a table and then into an arraylist?

    I'll try the example and go from there...
     
  7. Mr_Gee

    Mr_Gee Active Member Licensed User

    It all depends on how you have your data structured and what you want to do with it...

    I think the 1st option is the nicest,
    since you are populating only the required data..
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice