Visual Basic - Break Processing

Download Report

Transcript Visual Basic - Break Processing

Visual Basic - Break Processing
Be sure to open the speaker notes
when viewing this presentation
Input/Output
Minor Total Processing
This is the
input data each record
on the file
contains a
dept # and an
amount.
Dept #
Dept
12
12
12
15
15
15
15
17
17
Amount
500
100
50
200
100
300
60
20
240
12
12
12
Total 12:
15
15
15
15
Total 15:
17
17
Output report that is produced containing
the input records and a total each time the
department number changed.
Total 17:
Final Total:
Amount
500
100
50
650
Records from
department
12.
Total for
department 12.
200
100
300
60
660
20
240
260
1570
Final total for all
departments.
Minor break logic
•
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
–
–
–
•
Logic of Minor Break 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
NOT EOF
INPUT deptno, amt
set up and write
minor line
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
holddept < >
deptno
holddept < >
““
set up and write
final line
At EOF, the
minor total
for the last
group must
be written
followed by
the final
total line.
Set:
holddept=
deptno
setup and write
minor line
Reset:
holddept = deptno
mintot = 0
setup and write
detail line
add to minor &
final accums
Processing the
detail record
involves writing a
line and adding to
the accumulators.
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.
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 = “”.
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.
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
I compare to see if the contents of the hold area for
If Not EOF(1) Then
department is NOT equal to the dept # I just read and
Input #1, deptno, amt
to make sure the hold area isn’t empty. Empty tells me
If holddept <> deptno Then
this is the first record being processed, not a break.
If holddept <> "" Then
picOutput.Print "Dept Total:
"; Format(mintot, "Currency")
holddept = deptno
If both IFs true, then a break has happened. I print the break
mintot = 0
information and reset the holddept to the deptno I just read and
Else
reset the minor total to 0.
holddept = deptno
End If
End If
picOutput.Print Tab(3); deptno; Tab(7); Format(amt, "Currency")
mintot = mintot + Val(amt)
After checking for breaks, I write the
fintot = fintot + Val(amt)
detail line and add to the minor total
Else
and final total accumulator.
MsgBox "End of File", vbOKOnly, "EOF"
picOutput.Print "Dept Total:
"; Format(mintot, "Currency")
picOutput.Print "Final Total: "; Format(fintot, "Currency")
End If
End Sub
When EOF has been reached,
If the hold area for department is not equal to
the minor total line for the last
the dept # I just read but the hold dept is equal
dept must be written. Then the
to spaces, then we are dealing with the first
final total line must be written.
record and we need to move the dept # on the
first record to the hold area for department.