vb.net - Populating 2D-Arrays from CSV (without m*n-Loops) -


while migrating excel-vba project visual basic 2010, came across problem when populating arrays.

in excel-vba like

function mtxcorrel() variant     mtxcorrel = wscorr.usedrange end function 

to read m*n-matrix (in case n*n), conveniently stored in worksheet, array further use.

in vb2010 won't use excel-worksheet storage. csv-files (see below) seem decent alternative.

i want populate 2d-array csv-contents without looping n*n-times. let's assume know n=4 demonstration purposes.

this suggests want cant done.

nevertheless still hope following work:

function mtxcorrel() object      dim array1(4, 4) string      using ioreader new microsoft.visualbasic.fileio.textfieldparser("c:\cm_koma.csv")          ioreader             .textfieldtype = fileio.fieldtype.delimited             .setdelimiters(";")            ' here want to...           ' a) ...either populate whole 2d-array             array1 = .readtoend()            ' b) ... or populate array looping 1d-"rows"             while not .endofdata                 array1(.linenumber, 0)= .readfields()             end while          end     end using      return array1 end function 

notes:

  • i'm interested in populating array.
  • i'm less interested in potential errors determining csv-line belongs 1d-"row", , not interested in checking n.

appendix: sample csv-file:

1;0.5;0.9;0.3 0.5;1;0.6;0.2 0.9;0.6;1;0.1 0.3;0.2;0.1;1 


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -