Results 1 to 6 of 6

Thread: Text files too big for VB to handle

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7

    Text files too big for VB to handle

    I am trying to write a program that loads a text file into
    a richtextbox control by looping through the text one line
    at a time. Each line is first compared with a default value,
    say "". If the line matches then Don't print it to the screen.
    When I run my code with small files it works just fine, but
    when I run the code on a 2M text file, it takes hours. In fact
    I've never seen it finish on pass on this file. There has to be
    a more efficient method than the one I'm using.

    Dim m_filename As String
    Dim FileData As String
    Dim TotalFile As String

    Open m_filename For Input As #1

    Do While Not EOF(1)
    Line Input #1, FileData

    If FileData = "" Then
    ' Do nothing
    Else
    TotalFile = TotalFile & FileData & vbCrLf
    End If
    Loop

    RichTextBox1.Text = TotalFile

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Add each inputted line to an array, then JOIN the array at the end and add the JOIN'ed value to the box.

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    u could try something like this, and see if it speeds up the process..

    VB Code:
    1. Open fileName For Binary As #1
    2.             Text1.Text = Input(LOF(1), 1)
    3.         Close #1
    -= a peet post =-

  4. #4
    jim mcnamara
    Guest
    This is your problem:

    TotalFile = TotalFile & FileData & vbCrLf


    Try:
    Code:
    Dim m_filename As String 
    Dim FileData As String 
    Dim TotalFile() As String 
    Dim result() as string
    Dim final as string
    Open m_filename For Input As #1 
    FileData  = input(lof(1),1)
    close #1
    totalfile = split(filedata,vbcrlf) ' an array of lines
    for x = 1 to ubound(totalfile)
        if totalfile(x) > "" then 
            Redim Preserve result(ubound(result)+1)
            result(ubound(result)) = totalfile(x) & vbCrLf
        end if
    next x
    final = Join(result)
    ' final is now one giant string, like your old totalfile was

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Maybe I missed something but why not just use:
    VB Code:
    1. rtb.LoadFile App.Path & "\myfile.txt", rtfText

    You did say you are using a richtextbox right?

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7

    Why does totalfile = totalfile & filedata & vbCrLf cause a problem?

    Thanks

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