Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

Pull data from text file in vb6

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
Bob Schneider
Asked:
Bob Schneider
  • 2
  • 2
2 Solutions
 
HooKooDooKuCommented:
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
 
Bob SchneiderCo-OwnerAuthor Commented:
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
 
HooKooDooKuCommented:
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
 
Bob SchneiderCo-OwnerAuthor Commented:
Thanks so much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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