Hi all, i was wounding if anybody can help with this I’ll be really grateful
I’m working on a piece of software to read a comma separated text files with thousands of lines each line has around 32 word separated with a comma
What my code does at the moment it reads the file line by line choose 11 words out of the 32 and outputs them into a new file. This is actually time consuming although i used threads and a progress bar my manager still not happy.
So i was thinking if i can read the whole text file into a 2 dimensional array and then choose certain Colums to output on the new file that will make it work much faster. But i don’t know how to read a whole colum from a 2 dimensional array. And let’s say for example the array is gonna be like array(9500)(32) where the first argument representing the number of lines and the second represents the number of fields in each line.
Is there any way to access it like this array(all lines)(15)
I’m using vb.net 2008

Many thanks

Recommended Answers

All 2 Replies

if i understand correctly, try using this to load a text file into a 2-dim array

imports system.io
dim streamreader as streamreader
streamreader=file.opentext("c:\pathtofile.txt") 'or use an open file diag
dim filetext as string = streamreader.readtoend

dim yarray() as string
dim xarray() as string
yarray=filetext.split(environment.newline) 'slipt the file at line breaks: each line into each array segment'
for y = 0 to yarray.getupperbound
xarray = yarray(y).split(",") 'split into array segments from ,'s
for x = 0 to xarray.getupperbound
messagebox.show("The Value Is " & xarray(x) & " at X:" & x & "at Y:" & y)
next x
next y

let me know where this gets you

if i understand correctly, try using this to load a text file into a 2-dim array

imports system.io
dim streamreader as streamreader
streamreader=file.opentext("c:\pathtofile.txt") 'or use an open file diag
dim filetext as string = streamreader.readtoend

dim yarray() as string
dim xarray() as string
yarray=filetext.split(environment.newline) 'slipt the file at line breaks: each line into each array segment'
for y = 0 to yarray.getupperbound
xarray = yarray(y).split(",") 'split into array segments from ,'s
for x = 0 to xarray.getupperbound
messagebox.show("The Value Is " & xarray(x) & " at X:" & x & "at Y:" & y)
next x
next y

let me know where this gets you

Dear mrclark,
Thank you so much for ur respond but the problem wasn’t how to read the file into 2 dim array for me.
I’m gona use a table metaphor to make it easy for myself to explain.. i have a table with 9000 rows and 32 columns. Right now what I’m doin is goin thru each row and picking the 7,8,9,22,21,14,16,15,20 th values in each row to write into a new table. My question is there any syntax or code to help me read the table with columns instead of rows? For example i will select the 7th,8th,9th,22nd,21st,14th,16th,15th,20th from the whole table and write them into new table instead of goin thru the table line by line
of course i mean 2 dim array by a table

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.