Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Pull data from text file in vb6

Posted on 2014-04-16
4
Medium Priority
?
289 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 2000 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

886 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