Results 1 to 3 of 3

Thread: reading .txt-file

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Location
    germany
    Posts
    10

    reading .txt-file

    Hey, I want to walk through a .txt-file line by line, for- and backwards. I want to do that using the fseek function I know from c/c++. How do I declare that function in vba? I know how to add and declare SendMessage, CreateFile and others but how can I do that with fseek?
    Thanks,
    Alex.

  2. #2
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: reading .txt-file

    Originally posted by alexander_fleck
    Hey, I want to walk through a .txt-file line by line, for- and backwards. I want to do that using the fseek function I know from c/c++. How do I declare that function in vba? I know how to add and declare SendMessage, CreateFile and others but how can I do that with fseek?
    Thanks,
    Alex.
    you can open the file as binary and use Get to access a particular byte of data directly from the file.
    as far as access in a line from a file with lines of varying length I dont know of a way to do that directly to/from the file. A good alternative is to read the file into a stringvariable then use:
    Split(myString,vbcrlf) to get it into an array ... then you can access Line x directly from the array
    myArray(x-1)
    when you are done you just revers the procedure:
    Join(myArray,vbcrlf) then write it back to the disc ...

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Location
    germany
    Posts
    10

    reading .txt file

    Thanks,
    I tried it and it works, but needs a lot of resources.
    I now do it the old way, reading one line after the other. When I want to get the last line backwards I close the file, open it again and then read the lines until the chosen one is reached. It needs a lot of time, but doesn' t eat my memory. My application isn' t time related. It doesn' t matter if it needs more time, but my files are very big, because they offer measuring data.
    Thanks,
    Alex.

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