|
-
Apr 5th, 2002, 04:59 PM
#1
Thread Starter
New Member
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
-
Apr 5th, 2002, 05:00 PM
#2
Add each inputted line to an array, then JOIN the array at the end and add the JOIN'ed value to the box.
-
Apr 5th, 2002, 05:01 PM
#3
-= B u g S l a y e r =-
u could try something like this, and see if it speeds up the process..
VB Code:
Open fileName For Binary As #1
Text1.Text = Input(LOF(1), 1)
Close #1
-
Apr 5th, 2002, 05:06 PM
#4
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
-
Apr 5th, 2002, 05:14 PM
#5
Maybe I missed something but why not just use:
VB Code:
rtb.LoadFile App.Path & "\myfile.txt", rtfText
You did say you are using a richtextbox right?
-
Apr 5th, 2002, 05:18 PM
#6
Thread Starter
New Member
Why does totalfile = totalfile & filedata & vbCrLf cause a problem?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|