Solved

Pull data from text file in vb6

Posted on 2014-04-16
4
272 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now