Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Get Last Record Number in a Flat File.

Status
Not open for further replies.

vbboy

Programmer
Mar 7, 2001
4
US
Hi Friends,
I have a big text file of over 300,000 records in it. Is there a way to get the last record number without going through each record?

Thank you
 
Perhaps, perhaps not. Could depend on the nature / structure of the File.

If the records are "Fixed Length", you can retrieve the last record by defining it as a random access file, simply retrieveing the record and examining the record number. To do this, review the GET function in help (or elsewhere). While not currently popular, this was (once upon a time, long ago and far away) one of the more common approaches to saving/restoring data in many basic programs.

But then again, if it is truly a fixed length file of "data" records a sophisticated program may have stored the records in some order besides "record number", in which instance, knowing the record number of the "last" record doesn't even approach the answer, so that could be much ado about nothing.

On the other hand, the program could be set up to never delete any records and always and only ever add records which are sequentially numbered starting from a specific integer (actually Long Ingeger) value, so just knowing the number of LINES in the data file gives a good approximation of the record number of the last record.

Finally, while it would 'read' all of the records, you could just open the file in word pad and look/search for the record number.

Personally, I would go ahead and generate the function to read the record into memory. If you are going to ever use this information, you will need to be able to do this. Then, I would read all of the records and place them in a data structure, and do a number of check/tests/validations/correction processes on the information to be sure that it was "as represented" to me. Then I would PROMPTLY save this in a more convenient manner (e.g. the closest relational database closet). Proceede directly to the next step of generating the program to deal with the relational database structure and 'loose' all memory of the arcane methodology used to interrogate the flat file thinnggyyyy.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top