Solved

Pull data from text file in vb6

Posted on 2014-04-16
4
285 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
[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
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

738 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