Reading and displaying VERY large text file...

Z

zoneal

Size of text file to read and display can be larger than 10MB.
Since I must ignore certain input text lines the code I'm using is:

FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)

'Read text file and load into LineOfText

Do Until EOF(1) 'read lines from file

LineOfText = LineInput(1)

'Ignore lines =< 3 characters long

If Len(LineOfText) > 3 Then

'add each line to the RichTextBox1 variable

RichTextBox1.Text = RichTextBox1.Text & LineOfText & vbCrLf 'display
file

End If

Loop



Alternatives to using the code:

RichTextBox1.Text = RichTextBox1.Text & LineOfText & vbCrLf

may be required since I suspect it may be the cause - not sure.



Thank you for any and all suggestions.
 
H

Herfried K. Wagner [MVP]

Size of text file to read and display can be larger than 10MB.
Since I must ignore certain input text lines the code I'm using is:

FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)

'Read text file and load into LineOfText

Do Until EOF(1) 'read lines from file

LineOfText = LineInput(1)

'Ignore lines =< 3 characters long

If Len(LineOfText) > 3 Then

'add each line to the RichTextBox1 variable

RichTextBox1.Text = RichTextBox1.Text & LineOfText & vbCrLf 'display
file

You may want to use the richtextbox control's 'AppendText' method:

\\\
Me.RichTextBox1.AppendText(LineOfText & ControlChars.NewLine)
///

When choosing this approach, I suggest to disable redrawing for the control
while filling it:

Preventing controls from redrawing
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=disableredrawing&lang=en>

Maybe it's even faster to build the whole string in a 'StringBuilder' object
and then assign the final content once:

\\\
Imports System.Text
..
..
..
Dim sb As New StringBuilder()
#for each line in the file#
#if line is valid#
sb.Append(Line)
#endif#
#endfor#
Me.RichTextBox1.Text = sb.ToString()
///
 
C

Cor Ligthert [MVP]

Herfried,

Will you do me a pleasure ?
I don't think that using 'StreamReader' instead of VB.NET's file access
function will speed up the code a lot.
Will you read it again, I can be confusing however I thought that it is
quiet clear what I wrote.

:)

Can happen

:)

Cor
 
H

Herfried K. Wagner [MVP]

Cor,

Cor Ligthert said:
Will you read it again, I can be confusing however I thought that it is
quiet clear what I wrote.

:)

Ooops -- sorry... Thanks for making me aware of that :).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top