Results 1 to 5 of 5

Thread: Handle large text file superfast

  1. #1

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Handle large text file superfast

    Hi all,

    I have a large text file like 50000 lines (minimum). My program reads this file and do some modification in each line and write it to another text file.

    That's what I do?

    Normally if the text file has only 100 lines then it takes only 2 seconds to process it. But if the file is large then it takes even 10 seconds to process each 100 lines.

    How to fix this issues? I need to keep the process time as 2 seconds for each 100 lines for any number of lines.

    show me the best way to do this.

    Thanks in advance.
    CS

  2. #2
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Handle large text file superfast

    How are you currently reading the file? Please post some code.

  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Handle large text file superfast

    Did you try reading the file at once? something like..
    VB Code:
    1. Dim FileContent  As String
    2. Open "C:\file.txt" For Input As #1
    3.       FileContent = Input(LOF(1), 1)
    4. Close #1
    5.  
    6. 'or..
    7.  
    8. Dim tmp As String
    9. Open "C:\file.txt" For Binary As #1
    10.       tmp = Space(LOF(1))
    11.       Get #1, , tmp
    12. Close #1
    then you could split using vbNewLine, select the line to modify (an index of the array), modify it, and then write back to file.

  4. #4
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    Re: Handle large text file superfast

    the faster way to process text files is via the line input function.
    your number's seem a little slow, how much work are you doing on each line?

    i have an app that scans 250,000 line txt files, and on a match, pulls various info into 5 vars of different types.
    it returns 5000 matches from 250,000 lines in 1.3 seconds.
    post your code, and we can probably help you a lot more.

  5. #5
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Handle large text file superfast

    Would this work?
    VB Code:
    1. Dim FF_Read As Integer
    2. Dim FF_Write As Integer
    3. Dim StrTxt As String
    4.  
    5. FF_Read = 1
    6. FF_Write = 2
    7.  
    8. OriginalFile = "D:\File.txt"
    9. NewFile = "D:\NewFile.txt"
    10.  
    11. Open OriginalFile For Input As #FF_Read
    12. Open NewFile For Output As #FF_Write
    13.     While Not EOF(FF_Read)
    14.         Line Input #FF_Read, StrTxt
    15.         StrTxt = StrReverse(StrTxt)   'Change the text
    16.         Print #FF_Write, StrTxt
    17.     Wend
    18. Close #FF_Read
    19. Close #FF_Write
    Last edited by Andrew G; Jul 16th, 2006 at 02:07 AM.

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