Solved

Pull data from text file in vb6

Posted on 2014-04-16
4
278 Views
Last Modified: 2014-04-16
I have a file called "192.168.1.106.txt" that is being continuously appended with data (it is an rfid timing system file and as runners finish their time is added to the file).  What I want to do is repeatedly access the data in the main file without changing it.  So an idea I got on this site was to copy the entire file to a new file, names "the_time_I_accessed_it.txt" and then determine which is new data and grab that.

The data in the new file comes in like this: 1,907,0,"08:51:37.869",1,1

Is there a way to quickly determine which records are new?  What I do is write it to an array and parse it as per the diagram.  My idea, as given to me on this site, is to copy the entire file to a new file and then "work" on that.  Always looking for a better approach.  Again, I can't modify the original file
rfid-screen.docx
0
Comment
Question by:Bob Schneider
  • 2
  • 2
4 Comments
 
LVL 16

Assisted Solution

by:HooKooDooKu
HooKooDooKu earned 500 total points
ID: 40003867
So an idea I got on this site was to copy the entire file to a new file, names "the_time_I_accessed_it.txt" and then determine which is new data and grab that.
Sounds like a really bad idea because you wind up copying the same "old" data over and over.

You have the ability to seek (i.e. jump) to any point in a file, so why not simply "remember" how big the file was last time you read the data, and simply jump to that point.

You could still make a copy if you needed... but rather than calling a simple file copy command, you open the one file, seek to where you left off, then copy everything from that point in the file to the end.  Exactly HOW you do that depends upon the contents of the file and whether you open it as a text document (where you read things in a line at a time) or in binary mode where you read in blocks of data.  But still, trivial code to write a subroutine to open the file (say in binary), seek to the last point you left off, read a block of data, write that block of data to another file, repeat until you reach the new end of the file.

The other option (still maintaining where you left off) would be to open the file, seek past the last entry you read, read one more entry, and close the file.  Then you could use file size to determine if there is more data to read (so you have to maintain the location you last read to, as well as how big the file is).
0
 

Author Comment

by:Bob Schneider
ID: 40004116
Ok I am attaching two files.  The second one is the same as the first with more data added.  If you could sketch out the pseudo-code for your first idea that would be awesome.
192.168.1.159-1-.txt
192.168.1.159-2-.txt
0
 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 500 total points
ID: 40004629
Just one of the ways you could copy growing data to a new file would be with the following pseudo-code:
Dim LastOffset as Integer = 0
Dim FileNum as Integer
Dim Str as String

Do Until I say Quit

    'Get the next new line 
    FileNum = FreeFile
    Open 192.168.1.159-1-.txt for Input as FileNum
    If FileLength( FileNum ) > LastOffset Then
        Seek FileNumber LastOffset
        Str = ReadLine( FileNum )
        LastOffset = Seek FileNum 
    Else
        Str = ""  'No New Line available at this time
    End If

    'Append the new data to the 2nd file
    If Len(Str) Then
        FileNum = FreeFile
        Open 192.168.1.159-2-.txt for Output as FileNum
        WriteLine( FileNum, Str )
        Close FileNum
    End If
Loop

Open in new window

0
 

Author Closing Comment

by:Bob Schneider
ID: 40005620
Thanks so much.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

810 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