Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visual Basic - Break Processing

Similar presentations


Presentation on theme: "Visual Basic - Break Processing"— Presentation transcript:

1 Visual Basic - Break Processing
Be sure to open the speaker notes when viewing this presentation This slide show will deal with the logic of processing a file and producing output that includes a minor total line and a final total line.

2 Minor Total Processing
Input/Output Minor Total Processing This is the input data - each record on the file contains a dept # and an amount. Dept # Amount Total 12: Total 15: Total 17: Final Total: Records from department 12. Dept Amount Total for department 12. The input file is in order by dept #. When the dept # changes, we want to print out a total for that dept. When all records have been processed, we want to print out a final total line containing the total of all records processed. This is the same as saying the sum of all of the departments. Output report that is produced containing the input records and a total each time the department number changed. Final total for all departments.

3 Logic of Minor Break Processing
Minor break - logic Logic of Minor Break Processing Break processing involves printing totals when there is a change in processing caused by a new control number being read In this example the DEPT # is the control number The input file must be in order by the control number A hold area must be established to hold the control number to be compared against When a break occurs - MINOR TOTAL processing The minor total line is written The minor accumulator is reset to 0 for the next group The hold area is reset to contain the control number from the record that caused the break Processing of the individual record on the file - DETAIL processing Detail processing occurs when there is no break or after the break has been handled (minor total line written and accumulator and hold area reset) Detail processing consists of: Writing the detail record Adding to the minor accumulator Adding to the final accumulator At EOF The total for the last control group (in this case the last dept) must be written The final total must be written The logic of minor break processing is noted on this slide.

4 NOT EOF INPUT deptno, amt If the deptno on the input is not equal to the hold dept, we either have a break or it is the first record. Checking holddept for spaces handles this set up and write minor line holddept < > deptno holddept < > “ “ set up and write final line Set: holddept= deptno setup and write minor line At EOF, the minor total for the last group must be written followed by the final total line. Reset: holddept = deptno mintot = 0 This is the logic flowchart that goes with the code shown on the next page. If it is not EOF, we read a record. If the record deptno does not match the dept no in the hold area, we check to see if the hold area is empty. If it is not empty, we have a break and minor processing is done followed by dropping through to detail processing. If it is empty, then the deptno from the first record is moved to depthold and we drop through to detail processing. If the record deptno is the same as the holddept we drop through to detail processing. Finally when it is EOF, the minor total for the last group is written followed by the final total. If a break happened the minor total is written and the holddept is reset with the deptno that caused the break and the mintot is reset to 0 for the next group. setup and write detail line Processing the detail record involves writing a line and adding to the accumulators. add to minor & final accums

5 Minor break processing - VB code
In the general area, I dimensioned a variable for the minor total and the final total. I also set up a hold area for the dept so that I could compare and determine when a break has happened. Dim mintot As Integer, fintot As Integer Dim holddept As String Private Sub Form_Load() holddept = "" End Sub When the form is loaded I set the holddept = “”. This slide shows the establishment of a minor total accumulator and a final total accumulator and the establishment of a hold area called holddept. In the routine Form_Load, I initialized the holddept as empty. Note: In form load, the file would also be opened. Break processing calls for setting up accumulators to hold the totals you need to accumulate and a hold area to keep the data you are comparing to in order to determine if a break has happened. That hold area should be initialized so it is empty.

6 Minor break processing - VB code
If it is not EOF, I read from input #1 (note that this would have been opened when the form was loaded) and store in deptno and amt. Private Sub frmProcess_Click() Dim deptno As String, amt As String If Not EOF(1) Then Input #1, deptno, amt If holddept <> deptno Then If holddept <> "" Then picOutput.Print "Dept Total: "; Format(mintot, "Currency") holddept = deptno mintot = 0 Else End If picOutput.Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) fintot = fintot + Val(amt) MsgBox "End of File", vbOKOnly, "EOF" picOutput.Print "Final Total: "; Format(fintot, "Currency") End Sub I compare to see if the contents of the hold area for department is NOT equal to the dept # I just read and to make sure the hold area isn’t empty. Empty tells me this is the first record being processed, not a break. If both IFs true, then a break has happened. I print the break information and reset the holddept to the deptno I just read and reset the minor total to 0. After checking for breaks, I write the detail line and add to the minor total and final total accumulator. This shows the logic of the minor break processing. The logic involves three IF statements. IF it is not EOF, I input a record and then check for a break. (The second and third IF statements are involved in checking for the break). If a break has happened then a minor total line is processed and both the hold area and the minor accumultor are reset. If a break happened, but the third IF discovers it is the first record, not total line is printed. The hold area is set to hold the dept # from the first record. If no break happened OR after I have finished dealing with the break, I write out the detail line and add to the minor and final accumulators. The ELSE on the first IF means it is EOF and the total for the last dept as well as the final total are processed. When EOF has been reached, the minor total line for the last dept must be written. Then the final total line must be written. If the hold area for department is not equal to the dept # I just read but the hold dept is equal to spaces, then we are dealing with the first record and we need to move the dept # on the first record to the hold area for department.


Download ppt "Visual Basic - Break Processing"

Similar presentations


Ads by Google