vb.net - How to read tab separated values and put them into List? -


i have text file containing tab separated values load array or list can work values further. have used solution presented here , believe close need, in file first value on each line date , time stamp, each other value on line double.

for temporary testing attempting load values data grid view control, getting error input string not in correct format. need sort values later date/time need load values in unsure how accomplish this?

private function loadfile(byval filepath string) list(of list(of double))      'look @ text file , load stored values list      dim records new list(of list(of double))()     each line string in file.readalllines(filepath)         dim values new list(of double)()         each field string in line.split(new string() {controlchars.tab}, stringsplitoptions.none)             values.add(double.parse(field))         next         records.add(values)     next      return records  end function  private sub btnload_click(sender object, e eventargs) handles btnload.click      dgvvalues.datasource = loadfile(strfullpath)  end sub  private sub clbfilelist_itemcheck(sender object, e itemcheckeventargs) handles clbfilelist.itemcheck      strfilename = clbfilelist.selecteditem.tostring     strfullpath = strsourcepath + "\" + strfilename  end sub 

here few lines sample i'm trying read in program:

12:18:30 02-28-2014    189.233333333333    666.35  12:33:30 02-28-2014    274.716666666667    1111.35  12:48:30 02-28-2014    265.516666666667    1052.9  13:03:00 02-28-2014    253.583333333333    1164.25 

class mystuff    public property thedate datetime    public property onevalue double             public property twovalue double     ' optionally add constructor    ' create object @ once:    public sub new(dt datetime, v1 double, v2 double)        thedate = dt        onevalue = v1        twovalue = v2    end sub  end class 

elsewhere:

public stufflist new list(of mystuff)   dim el mystuff ' presumably in loop:  ' after parse text date , doubles: el = new mystuff(dateread, val1read, val2read) stufflist.add el 

even more compact, no temp element var (above more illustrative of process):

stufflist.add(new mystuff(dateread, val1read, val2read)) 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -