Solved

Delete Line In Text File with vb6

Posted on 2014-12-07
9
468 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 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
Comment Utility
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 68

Assisted Solution

by:Qlemo
Qlemo earned 300 total points
Comment Utility
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
Comment Utility
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
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 300 total points
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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 68

Accepted Solution

by:
Qlemo earned 300 total points
Comment Utility
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 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
Comment Utility
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
Comment Utility
Thank you very much.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

763 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

13 Experts available now in Live!

Get 1:1 Help Now