By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

Open a text file and into an array ??

P: n/a
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
Feb 12 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

Feb 12 '06 #2

P: n/a

"tomb" <to**@technetcenter.com> wrote in message news:NJ****************@bignews8.bellsouth.net...
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.
Feb 13 '06 #3

P: n/a
Jason wrote:


"tomb" <to**@technetcenter.com <mailto:to**@technetcenter.com>>
wrote in message news:NJ****************@bignews8.bellsouth.net...
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.

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
Feb 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.