Results 1 to 7 of 7

Thread: start the reading file from...

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,941

    start the reading file from...

    I use the tipical function:
    ....
    Open file For Input As #1
    ...
    ecc...

    to reading txt file line by line.

    But instead to init the redaing line by line...

    1) I need to find, in position mid(line, 1,8), the string INIT0000 and strat the reading of lines from here
    2) stop the reading of line from file wehen the code found in mid(line, 1,8), the string INIT0001

    please a fast method to find the first line because have perphs 2.300.000 of lines in original txt file

    note:
    no possible duplicate string in position mid(line, 1,8)

  2. #2
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: start the reading file from...

    this link may be helpful
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,941

    Re: start the reading file from...

    Quote Originally Posted by seenu_1st View Post
    this link may be helpful

    test exampe in link...
    But each code give error about memory...
    Remember i have aprrox 2.300.000 lines in txt file

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: start the reading file from...

    Unless every line is exactly the same length, you have no way of being able to jump to a specific line in the file.

    Reading the entire file into memory works well for small files, not large files (depends on system resources)
    1. Either loop line by line until you get to the line you are looking for, or

    2. Open the file for BINARY and read a chunk of the file at once. You can play with the chunk size to optimize performance. Maybe start out at like 32kb at a time and go all the way to 500kb at a time
    - There are projects in the CodeBank section for searching a file quickly. Think those might help
    - The problem with searching chunks is that if the criteria you are searching for happens to be split between chunks. Solving this problem is easy enough, when criteria not found in current chunk, start reading the next chunk a few bytes (length of your criteria) before where the current chunk ended. By opening file as Binary, you can tell it where to start reading each time you attempt a read
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,941

    Re: start the reading file from...

    Quote Originally Posted by LaVolpe View Post
    Unless every line is exactly the same length, you have no way of being able to jump to a specific line in the file.

    Reading the entire file into memory works well for small files, not large files (depends on system resources)
    1. Either loop line by line until you get to the line you are looking for, or

    2. Open the file for BINARY and read a chunk of the file at once. You can play with the chunk size to optimize performance. Maybe start out at like 32kb at a time and go all the way to 500kb at a time
    - There are projects in the CodeBank section for searching a file quickly. Think those might help
    - The problem with searching chunks is that if the criteria you are searching for happens to be split between chunks. Solving this problem is easy enough, when criteria not found in current chunk, start reading the next chunk a few bytes (length of your criteria) before where the current chunk ended. By opening file as Binary, you can tell it where to start reading each time you attempt a read
    not for me tks friend

    can i send my txt file and chat in msger or skipe or fb?

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,941

    Re: start the reading file from...

    Quote Originally Posted by LaVolpe View Post
    Unless every line is exactly the same length, you have no way of being able to jump to a specific line in the file.

    Reading the entire file into memory works well for small files, not large files (depends on system resources)
    1. Either loop line by line until you get to the line you are looking for, or

    2. Open the file for BINARY and read a chunk of the file at once. You can play with the chunk size to optimize performance. Maybe start out at like 32kb at a time and go all the way to 500kb at a time
    - There are projects in the CodeBank section for searching a file quickly. Think those might help
    - The problem with searching chunks is that if the criteria you are searching for happens to be split between chunks. Solving this problem is easy enough, when criteria not found in current chunk, start reading the next chunk a few bytes (length of your criteria) before where the current chunk ended. By opening file as Binary, you can tell it where to start reading each time you attempt a read
    Friend have you see my last reply on this question...?

  7. #7
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: start the reading file from...

    You can start reading any specific line or byte location of a file, provided that you have a unique identifier that isolates the location for the initial read. Sometimes I first index huge files and establish the byte positions in a separate indexing file that I use to store those positions. Then I use either the Seek or Get statement to jump immediately to the location.

    Ending the read can then be accomplished by using a delimiter character that stops the reading by looking ahead using Instr(). In between is the string information that you need for your application.
    Doctor Ed

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