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 "). _
' Loop until end of stream is found
s = txtStream.ReadLine ' Read one line
txtDisplay.Text = txtDisplay.Text & vbNewLine & s
Loop While (txtStream.AtEndOfStream = False)
Call txtStream.Close ' Close TextStream
Private Sub Form_Load()
Call openAndReadFile ' Open and read file
Thank you for your replay, Marvels. I find a way to read bytes, it is pretty fast now.
const ForReading = 1
const TristateFalse = 0
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!"