Open a text file and into an array ??

J

Jason

Can someoneillustrate how I would open a text file that looks something
similar to this:
namea,8888,1234.99
nameb,8887,1242.50

and then after opening that file read each one of the values into an
array...namea and 8888 and 1234.99 would be three arrays

thanks
 
T

tomb

Jason said:
Can someoneillustrate how I would open a text file that looks something
similar to this:
namea,8888,1234.99
nameb,8887,1242.50

and then after opening that file read each one of the values into an
array...namea and 8888 and 1234.99 would be three arrays

thanks
Actually, it would be one array, with three indeces.

dim sline as string = lineinput(filepointer)
dim aline as array = split(sline,",")
Then you would have these values:
aline(0) = namea
aline(1) = 8888
aline(2) = 1234.99

Tom
 
J

Jason

Jason wrote:

Can someoneillustrate how I would open a text file that looks something
similar to this:
namea,8888,1234.99
nameb,8887,1242.50

and then after opening that file read each one of the values into an
array...namea and 8888 and 1234.99 would be three arrays

thanks


Actually, it would be one array, with three indeces.

dim sline as string = lineinput(filepointer)
dim aline as array = split(sline,",")
Then you would have these values:
aline(0) = namea
aline(1) = 8888
aline(2) = 1234.99

Tom
How would I actually open the file?....and then get that file to seperate into the array. Lets say the file name is test.txt
for example I want to store namea as strUser 8888 as dblaccess and 1234.99 as dblaccount

so I would like it to fill an array like this...
info(0).strUser = "namea"
info(0).dblaccess = 8888
info(0).dblaccount = 1234.99

and
info(1).strUser = "nameb"
info(1).dblaccess = 8887
info(1).dblaccount = 1242.50

and so on until the end of file.
 
T

tomb

Jason said:
"tomb" <[email protected] <mailto:[email protected]>>
wrote in message
Actually, it would be one array, with three indeces.

dim sline as string = lineinput(filepointer)
dim aline as array = split(sline,",")
Then you would have these values:
aline(0) = namea
aline(1) = 8888
aline(2) = 1234.99

Tom

How would I actually open the file?....and then get that file to
seperate into the array. Lets say the file name is test.txt

for example I want to store namea as strUser 8888 as dblaccess
and 1234.99 as dblaccount

so I would like it to fill an array like this...
info(0).strUser = "namea"
info(0).dblaccess = 8888
info(0).dblaccount = 1234.99

and
info(1).strUser = "nameb"
info(1).dblaccess = 8887
info(1).dblaccount = 1242.50

and so on until the end of file.
Why do you need it in an array?
I ask only because in order to dimension the array at the start, you
would need to know how many lines of data you have. While you could
keep redimensioning the array with every line you read, that would be a
serious resource hog. You might want to consider putting the data in a
datatable and working with it that way. Or just read and process one
line at a time, as my original illustration would do.

T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top