System Buffer Management Methods (Advanced)

Sometimes it is not enough to operate on a per record basis. Let's assume that your input text consists of the following text areas:

  219434342  GASKET SET       123.35    3      370.05     19980301     19980630

  798734776  OIL PUMP         345.23    1      345.23     19970403     19960704

  872375762  VALVE GUIDE       10.25    8       82.00     19980523     19980723

  897987237  VALVE SPRING       4.95    8       39.60     19980523     19980723

  987987765  PISTON SET       805.00    2    1,610.00     19980523     19930913

SUBTOTAL ENGINE PARTS                  22    2,446.88         

  987293744  TORSION BAR      218.50    2      437.00     19980427     19981010

  098230984  SWAY BAR         399.00    1      399.00     19981010     19970119

  958430987  CV JOINTS        318.75    3      956.25     19881112     19980909

  092834844  STRUT ASSEMBLY   449.00    3    1,347.00     19970617     19970530

SUBTOTAL SUSPENSION                     9    3,139.25

and we would like to merge the subtotal information for each group into each detailed record. The methods, which accumulate, query and extract the data from the system buffer can facilitate the task.

First of all, we do not want TextConveter to insert any output records into the database until we encounter a closing line for each text block.  Therefore we call SkipRecord at the beginning of the OnRecord method implementation (line 2).  Then we accumulate all input records in the system buffer (line 16) until we encounter a closing line (line 5). After that we iterate through all of the accumulated records (line 6), take some data from the closing line (lines 7-9), fetch an input record from the buffer (line 10) and get some more data for each detailed record (lines 11-12). Now we can insert an output record into the output database table (line 13). We flush the system buffer (line 15) to get ready for the next block of records.

 1. Function OnRecord

 2. this.SkipRecord()

 3. Dim input

 4. input = DictIn.Field_1.value

 5. If Left(input, 3) = "SUB" Then

 6.      For I = 0 To this.GetBufferCount() - 1

 7.          DictOut.GroupName.value = Mid( input, 10, 25 )

 8.          DictOut.GroupQty.value    = Mid( input, 43, 4 )

 9.          DictOut.GroupCost.value  = Mid( input, 49, 10 )

10.          this.GetFromBuffer( I )

11.          DictOut.ItemNo.value  = Mid( DictIn.Field_1.value, 3, 9 )

12.          DictOut.Descript.value = Mid( DictIn.Field_1.value, 14, 19 )

13.          this.AppendRecord()

14.     Next

15.     this.FlushBuffer()

16. Else this.AddToBuffer()

17. End If

18. End Function

Back (This. Methods) | Next (this.AddToBuffer)