Best way to loop through records and store summary for multiple fields

vgehts

New member
Joined
Oct 27, 2007
Messages
1
Programming Experience
10+
I have the following scenario and need some guidance. I am passed a bucket of information from an outside source (text file) and need to transform it back in the form of multiple text files, that have special headers at the begin of each grouping and then raw data output for each transaction in the source plus summary information.

The source data has the following fields in tab delimited format
OutputID, ContractID, SourceID, UserID, ItemCode, ItemCount, ItemAmount

The data comes in sorted by the first four fields. All data for a given OutputID goes into one text file. For each UserID, I have to output a header and then each ItemCode/ItemCount/ItemAmount line and after outputting all of the records for a given UserID, also output a summary section that basically shows sum of itemcount and item amount for each item code. So if the ItemCode, ItemCount and ItemAmount (there is no correlation between the ItemCount and ItemAmount fields) portion of the file looks like this:
Apple 5 25.00
Orange 4 3.00
Grape 6 10.00
Orange 3 3.00
Orange 5 4.00
Grape 4 8.00
Apple 5 1.00
Grape 2 20.00

Then the summary portion would look like this
Apple 10 26.00
Grape 12 38.00
Orange 12 10.00

The ItemCodes are not sorted and must be processed and output in the order received. In addition, there is no static set of itemcodes. In other words, one day it might be apple/grape/orange, but then the next day there might be two more item codes. I must, however, sort the summary information. In addition, after the data for all UserIDs of a given ContractID have output, I have to create a summary at the ContractID level, that looks like this:

UserIDABC Apple 10 26.00
UserIDABC Grape 12 38.00
UserIDABC Orange 12 10.00
UserIDXYZ and so on and so on.

My background is with Visual Foxpro and I can easily handle all of this with mutli-dimensional arrays and rely on FoxPro's capability to perform searches on just the first colum of a multi-dimensional array in order to add to the sum values as I go through the data. However, it appears that VB's Array.IndexOf() only works on single dimension arrays. I've been playing around with creating structures to hold the two types of summary information and doing something with collections, but I think I'm over thinking the whole thing.

What direction would you all point me into for accomplishing the summary of these two groups of data (one at the UserID level and another at the ContractID level) so that I can output the two summaries.
 
Last edited:
Back
Top