Delete Line In Text File with vb6

I want to take a potentially large text file that has records like this:


and I want to delete all rows that have a specific bib number (the 396, 229, etc) if the time is earlier than a specific time.  I want to do this using fso and vb6 by entering the bib to find and the time that is the "cutoff" for that bib.

How can I do that?
Bob SchneiderCo-OwnerAsked:
Who is Participating?
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
At that size it is probably sufficient to read the fike into memory as a whole, then split at newline and then again at comma to get two-dimensional arrays with individual fields. Then perform simple String compares - since you only have times (no dates), less and greater checks on strings are ok.

Depending on the exact condition you can
- either process the array in multiple goes, removing the unwanted data for one bib after the other (e.g. if the time portion to check against is different for each bib), and write out the remaining data in the array after being thru,
- or check against all bibs to exclude and write out the current line into the file.

You can also read the file line by line, deciding whether to keep that line (in memory) or dismiss it. And when gone thru the file, overwrite it with the array content.

All of that are basic (pun intended) operations ;-). At that file size the way you process it doesn't matter much. But you need to keep in mind that you can't read and write to the same file, so
- either you keep content in memory, and replace the file content in one go;
- or have to write to a temporary file, deleting or renaming the original;
- or rename the original file before processing, and write to the original file name.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
well, what is the specific problem/steps here?
* taking the user input
* reading the file
* parsing the line / deciding if it's a match or not
* writing the resulting file

note: with a plain text file, you cannot simply "delete" some lines, but only rewrite the full file
the safest way to do so is to write a new (temp) file (aka in a temp folder), and then just copy/move that file over the previous file (or copy first the old file to a .bak file, for example...)

please clarify which steps you have the problem (you know: divide a conquer is the way to solve)
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I suggest to use what is appropriate here: A Flat file Jetdriver connection, reading a CSV file, and handling it like a database table.
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Bob SchneiderCo-OwnerAuthor Commented:
OK so assume I have a text file with 5,000 rows that look like the three above.  How would I use that to delete a line from the text above where the second value is 229 and the time field is less than 14:55:09.142.  I would like to do this programatically in vb6.  It would likely have to be done multiple times in a session with different values.
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
At 5000 rows you should process each row, then decide whether it meets any of the "delete" criteria, and write out if not.
Which size is the file? How much memory is available (to potentially keep all data in memory)?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
please, again: what is the exact problem you are having.
EE is not a rent-a-coder platform, so you need to check the steps, and tell use which exact step you are having with.
Bob SchneiderCo-OwnerAuthor Commented:
I time races and my rfid timer generates a text file with records as per above.  I want to be able to delete records from a text file from within my vb6 application that are not wanted.  In this case, a typical file size is 140kb.  The problem is not one of size, but one of the record existing when I look for the line of code that will represent this person's, or relay team's, actual finish time.  I am just wondering if this is something that is easily done or not and, if so, how it would be approached.

I like to ask these questions and then filter the responses before I plow through on my own.  Many, many times something that I thought wouldn't work/couldn't be done was fairly straightforward after posting to this site.  I learn a lot of new processes...for instance "Flat file Jetdriver connection, reading a CSV file, and handling it like a database table."

I understand that Experts Exchange is not a "rent-a-coder" but I also understand that i pay a monthly fee for this service.    I am asking a question that I need an answer to if I can find one...otherwise I will move in a new direction.  You can choose to help or not, but I can do without the glib comments.  Thankfully that almost never happens on this site.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I will not discuss about the money you pay, please double-check that with EE community support.
I am not paid at all by EE, just to note,

well, I just made now some 10 seconds google searches about the different steps:
VB6 read file line by line:
VB6 split line:
VB6 write text file:
VB6 move/name files, I prefer the FSO object (which also allows the read and write from above):
Bob SchneiderCo-OwnerAuthor Commented:
Thank you very much.
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.

All Courses

From novice to tech pro — start learning today.