Results 1 to 2 of 2

Thread: Jump to a specific line in a text file

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    4

    Jump to a specific line in a text file

    Hi,

    I have a huge text file that I need to read a specific line. The file has 5671 rows and 7743 columns, so it is too big to put into an array quickly. I know which row that I want to read, but I only know how to read from the first row down, so by the end it takes forever.

    Here is the code:

    aDEMFile = "C:\temp\dem300ft.txt"
    iFileNum = FreeFile
    Open aDEMFile For Input As iFileNum

    'if the position to go to is ahead of the current
    'pointer, then move ahead to that position.
    If Yposition > tempPosition Then
    For i = tempPosition To Yposition - 1
    Line Input #iFileNum, str
    tempPosition = tempPosition + 1
    Let Position = tempPosition
    Next
    ...

    Can you jump to a specific record?

    Is there a better way?

    Or can I easily load this into an array? (it takes forever to load into the array now)

    Thanks, Chris

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Jump to a specific line in a text file

    Does this file have a certain structure? Is each row fixed length or variable?
    If the file has a specific structure using Seek would be perfect.

    If the file is variable you could still use Seek but it would be guess work. Something like

    Seek to Position * Average length of Row
    Move Byte by Byte until you hit a CRLF.
    Then start using Line Input as you are now.

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