?
Solved

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

Posted on 2003-03-11
7
Medium Priority
?
391 Views
Last Modified: 2010-05-01
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
Comment
Question by:Illydth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 27

Assisted Solution

by:Dabas
Dabas earned 100 total points
ID: 8116264
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
 
LVL 2

Accepted Solution

by:
spauljoseph earned 100 total points
ID: 8117516
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
 
LVL 2

Expert Comment

by:spauljoseph
ID: 8117520
NOTE: you can use the Command1_Click event as the Timer1_Timer event for automatic checking.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Illydth
ID: 8121102
Thank you VERY much guys, this is pretty much exactly what I was looking for.

--Doug
0
 

Expert Comment

by:CleanupPing
ID: 8900261
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 9097157
Moderator, my recommended disposition is:

    Split points between: Dabas and spauljoseph

DanRollins -- EE database cleanup volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question