Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    3

    Unanswered: VB Program to read a large sequential file (tar file)

    I need write a VB program to read a large .tar file as a sequential file, this file is about 10MB, I wrote a program to read each line and display them in a text box, but everytime when I run my program, it froze the computer, the program become not responding because the file is too large. My code is as following, how to deal with this problem and read a large file?

    Option Explicit ' General declaration
    Dim mFso As New FileSystemObject

    Private Sub openAndReadFile()
    Dim txtStream As TextStream, s As String

    txtDisplay.Text = "Accounts:"

    Set txtStream = mFso.GetFile("c:\VBCode\vbhowtoprogram\clients.tar "). _
    OpenAsTextStream(ForReading)

    ' Loop until end of stream is found
    Do
    s = txtStream.ReadLine ' Read one line

    txtDisplay.Text = txtDisplay.Text & vbNewLine & s

    Loop While (txtStream.AtEndOfStream = False)

    Call txtStream.Close ' Close TextStream
    End Sub

    Private Sub Form_Load()
    Call openAndReadFile ' Open and read file
    End Sub

  2. #2
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    Lightbulb Hi There

    first try to see if you can read/ count the lines in the file (show them in a label)

    then let loose you function and count the lines as you go along

    Because 10Mb is a lot off lines it can seem that your stuck but in fact your not

  3. #3
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    and use the doevents

    here and there use the

    DoEvents
    So you can swithc between programs and stuff

  4. #4
    Join Date
    Jan 2004
    Posts
    3
    Thank you for your replay, Marvels. I find a way to read bytes, it is pretty fast now.

    const ForReading = 1
    const TristateFalse = 0
    dim strSearchThis
    dim objFS
    dim objFile
    dim objTS
    set objFS = Server.CreateObject("Scripting.FileSystemObject")
    set objFile = objFS.GetFile(Server.MapPath("myfile.txt"))
    set objTS = objFile.OpenAsTextStream(ForReading, TristateFalse)

    strSearchThis = objTS.Read(objFile.Size)

    if instr(strSearchThis, "keyword") > 0 then
    Response.Write "Found it!"
    end if

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •