• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 415
  • Last Modified:

How to Read info from a text file Real-Time into a control.

All,

Using VB 6.0, do not have access to VB.Net

Questions:
1) Is there a better control than an RTF Box to read large (> 5 Meg) amounts of text into.
2) Is there a control that I can append data to without having to re-load the entire set of data each time a new line is added.
3) How do I access new information in a file that is constantly changing without having to re-open/re-parse the entire file.

     Ok, just a quick FYI as to why i'm asking.  I'm attempting to write a Log file parser for a log that is updated in real time.  In other words this program needs to be able to run and display information to my screen as the log file changes through another application.

Here's the problems:  
1) The Log file can be huge - 10 - 20 meg is not uncommon.
2) This needs to run real time and not take too much time to load as this is supposed to be a "behind the scenes" part of the application.  There will be other stuff the user can do while this file is being read in.
3) I'm hoping for a way to load this line by line instead of en-mass.  I would prefer to be able to color each line as it is read in when displayed in an RTF Box (unless there's a better control) based upon the contents of the line.


Any information about this would be GREATLY appreciated.  I have both C/C++ and VB knowledge, but I don't know C++ Windows programming well enough to create windows/items in it...so i'm stuck with VB for the interface.

I can re-load the file based on a timer event into the RTF box, but that causes an application delay every x amount of time...and this really needs to be more real time than file/open.  

Any help or any information any of you could provide would be immensely helpful...thanks.
0
Illydth
Asked:
Illydth
2 Solutions
 
DabasCommented:
This is from help of the TextStream object (part of File System Object - References: Microsoft Scripting Runtime)

----------Start of Paste----------
ReadAll Method
         

Description

Reads an entire TextStream file and returns the resulting string.

Syntax

object.ReadAll

The object is always the name of a TextStream object.

Remarks

For large files, using the ReadAll method wastes memory resources. Other techniques should be used to input a file, such as reading a file line by line.

----------------------End of Paste------------

Seems to me that ReadAll would be a quick way to get the whole file in one go, but the remarks section would contradict it.

Give it a try though

Dabas
0
 
spauljosephCommented:
Try this.

NOTE: RichTextBox is the only control that can allow text larger texts. But you can use the following trick for reading the file only at the new lines and add them in the richtextbox's last lines only with automatic scrolling facility also. Try this and view the faster loading of any mega bytes.


'To test use a Form with a RichTextBox and a Command Button and a TextFile named LogFile.Txt with any number of lines in the same directory where you save this project.

'Add this code

Option Explicit

Dim lngLOF As Long
Dim lngLoc As Long
Dim strLine As String

Private Sub Command1_Click()
    Open App.Path & "\LogFile.Txt" For Input As #1
    strLine = ""
    If LOF(1) > lngLOF Then
        While lngLoc <= LOF(1)
            Seek #1, lngLoc
            strLine = strLine & input(1, #1)
            lngLoc = lngLoc + 1
        Wend
        lngLOF = LOF(1)
        RichTextBox1.SelStart = Len(RichTextBox1.Text)
        RichTextBox1.SelText = strLine
        RichTextBox1.SelStart = RichTextBox1.SelStart + Len(strLine)
    Else
        'No change in the Log File
    End If
    Close #1
End Sub

Private Sub Form_Load()
    lngLOF = 0
    lngLoc = 1
End Sub
0
 
spauljosephCommented:
NOTE: you can use the Command1_Click event as the Timer1_Timer event for automatic checking.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
IllydthAuthor Commented:
Thank you VERY much guys, this is pretty much exactly what I was looking for.

--Doug
0
 
CleanupPingCommented:
Illydth:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Split points between: Dabas and spauljoseph

DanRollins -- EE database cleanup volunteer
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now