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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting / Collecting Unique Entries in a File

Status
Not open for further replies.

hankm3

Programmer
Jan 27, 2002
284
US
Hello,

I'm attempting to Create a Script can open a Text that has been formatted with data and then collecting and counting each entry type and then sending them to a New Text file. Note that each Line is Constant so using the FSEEK Family of commands will work.

If this can't be done, will Excel 97 perform the Unique and Count Function. I can DDE the Formatted file to Excel if it can do this; but would rather do it in Aspect..

The Data File will look like this.

669-0900 SYSF
669-0900 GNCT
669-0900 BLDN
669-0900 SYSF
669-0100 SYSF
669-0100 BLDN
669-0900 SYSF

Results should be:

669-0900 SYSF 3
669-0900 GNCT 1
669-0900 BLDN 1
669-0100 SYSF 1
669-0100 BLDN 1

Any ideas welcome !

Hank camphm@bellsouth.net
 
Hey Hank here's a thought or two.

How about reading all of your data into an array. Then cycle thru the array counting all the distinct values.
You would have to set up an outer loop that loops thru the full array. Then an inner loop that loops thru an identical array and counts each individual value and then writes the info to file. You would have to keep track of which values you have already counted in an additional array.

Or maybe an even better idea would be import all your data into an array. Then sort it. Use maybe a bubble sort. I've written a couple in VB. The same logic would apply. I'm not quite sure on implementation though. After it's sorted you could simply cycle thru the array counting unique values. When the value changes write that info to file and reinitial you counter.

Just a couple of thoughts. I'm sure there are many different approaches you can take. Good Luck!

Matt
 
Thanks Matt,

I think I may have a Plan using Fseek, Ftell, and Fdelblock, since the Data is so Structured. I may be able to grab the First Entry, and use it to compare all the other Lines, and delete any matches after counting the Entries. Then Start all after writing the Entry and Count to a File.

Hank camphm@bellsouth.net
 
Hello,

Found the Solution. It works off the Fseek Family of Commands.

Hank camphm@bellsouth.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top