Solved

Delete Line In Text File with vb6

Posted on 2014-12-07
9
496 Views
Last Modified: 2014-12-08
I want to take a potentially large text file that has records like this:

3,396,396,"14:55:08.989",1,3
3,229,229,"14:55:09.142",1,3
2,2450,0,"14:55:12.199",1,2

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?
0
Comment
Question by:Bob Schneider
  • 3
  • 3
  • 3
9 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
ID: 40485450
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)
0
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 300 total points
ID: 40485525
I suggest to use what is appropriate here: A Flat file Jetdriver connection, reading a CSV file, and handling it like a database table.
0
 

Author Comment

by:Bob Schneider
ID: 40485653
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.
0
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.

 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 300 total points
ID: 40485675
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)?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40485682
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.
0
 

Author Comment

by:Bob Schneider
ID: 40485690
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.
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 300 total points
ID: 40485941
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.
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
ID: 40486174
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: http://www.vb6.us/tutorials/how-read-simple-text-files
VB6 split line: http://support.microsoft.com/kb/266289
VB6 write text file: http://www.vbtutor.net/vb6/lesson17.html
VB6 move/name files, I prefer the FSO object (which also allows the read and write from above):
http://www.vb6.us/tutorials/using-fso-file-system-object-vb6
0
 

Author Comment

by:Bob Schneider
ID: 40486660
Thank you very much.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

830 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