CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Posts
    76

    populate array from txt

    I loop txt file line by line with the simple free file do while eof ...loop ecc...

    From each line in txt file i get 5 value and assign it to var1, var2, var3, ...var5.

    I need to populate an array with value of each line until eof is true, how to?

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: populate array from txt

    Your question is rather unspecific.
    The best I could evaluate out of your description is this.
    As you do not seem to know how many lines there are in the file, you need a dynamic array.
    Next, each line in the file holds 5 values.
    The question is: Do you want to store each value in an individual array?
    It is not clear what you want to do.
    So you could do this:

    Code:
      Dim f%, n%, L$()
      f = FreeFile
      Open FileName For Input as #f
      While not EoF(f)
        redim preserve L(n)
        Line Input #f, L(n)
        n = n + 1
      Wend
      Close #f
      FreeFile f
    Now you have read all lines of the file.
    What you ever want to achieve with the individual lines is up to you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured