Home All Groups Group Topic Archive Search About

Open a text file and into an array ??

Author
12 Feb 2006 10:09 PM
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

Author
12 Feb 2006 10:36 PM
tomb
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
Author
13 Feb 2006 3:34 AM
Jason
"tomb" <t***@technetcenter.com> wrote in message news:NJOHf.7955$bW.1670@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.
Author
13 Feb 2006 4:25 AM
tomb
Jason wrote:

Show quoteHide quote

>
>     "tomb" <t***@technetcenter.com <mailto:t***@technetcenter.com>>
>     wrote in message news:NJOHf.7955$bW.1670@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