break processing please use speaker notes for additional information!

25
Break Processing Please use speaker notes for additional information!

Upload: erica-stokes

Post on 29-Dec-2015

219 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Break Processing Please use speaker notes for additional information!

Break Processing

Please use speaker notes for additional information!

Page 2: Break Processing Please use speaker notes for additional information!

Minor BreakMinor Break

Page 3: Break Processing Please use speaker notes for additional information!

Minor BreakMinor Break

Private Sub Form_Load() If Right(App.Path, 1) <> "\" Then Open App.Path & "\Minor.txt" For Input As #1 Else Open App.Path & "Minor.txt" For Input As #1 End If holddept = ""End Sub

When the form is loaded I am going to check the right most character of the path to see it is not equal to a slash. If the slash is not there then the path to the text file being read is opened as the current path concatenated with a slash and the name of the file. If the slash is already there then the file is opened as the application path including the slash followed by the name of the file.

“For the App object, Path specifies the path of the project .VBP file when running the application from the development environment or the path of the .exe file when running the application as an executable file.” Quote from the help file with Visual Basic.

The variable holddept which will be used with the break processing is set to null. It is defined in the general area so it is available in all Subs.

Minor.txt"12","500""12","100""12",”050""15",”200""15",”100""15","300""15",”060""17",”020""17","240"

Page 4: Break Processing Please use speaker notes for additional information!

Dim mintot As Integer, fintot As IntegerDim holddept As StringOption ExplicitPrivate Sub cmdExit_Click() EndEnd SubPrivate Sub Form_Load() If Right(App.Path, 1) <> "\" Then Open App.Path & "\Minor.txt" For Input As #1 Else Open App.Path & "Minor.txt" For Input As #1 End If holddept = ""End SubPrivate 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 holddept = deptno End If End If picOutput.Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) fintot = fintot + Val(amt) Else MsgBox "End of File", vbOKOnly, "EOF" picOutput.Print "Dept Total: "; Format(mintot, "Currency") picOutput.Print "Final Total: "; Format(fintot, "Currency") End If End Sub

Minor BreakMinor Break Minor.txt"12","500""12","100""12",”050""15",”200""15",”100""15","300""15",”060""17",”020""17","240"

Page 5: Break Processing Please use speaker notes for additional information!

Minor Total Processing

Dept Amount

12 500

12 100

12 50

15 200

15 100

15 300

15 60

17 20

17 240

Dept # Amount

12 500

12 100

12 50

Total 12: 650

15 200

15 100

15 300

15 60

Total 15: 660

17 20

17 240

Total 17: 260

Final Total: 1570

This is the input data - each record on the file contains a dept # and an amount.

Input/OutputInput/Output

Output report that is produced containing the input records and a total each time the department number changed.

Records from department 12.

Total for department 12.

Final total for all departments.

Page 6: Break Processing Please use speaker notes for additional information!

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

Minor break - logic

Minor break - logic

Page 7: Break Processing Please use speaker notes for additional information!

NOT EOF

holddept < >deptno

INPUT deptno, amt

holddept < >“ “

setup and writeminor line

Reset:holddept = deptno

mintot = 0

Set:holddept=

deptno

setup and writedetail line

add to minor &final accums

set up and writeminor line

set up and writefinal 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

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.

Processing the detail record involves writing a line and adding to the accumulators.

At EOF, the minor total for the last group must be written followed by the final total line.

Minor logicMinor logic

Page 8: Break Processing Please use speaker notes for additional information!

Private Sub Form_Load() ... holddept = ""End Sub

Minor break processing - VB codeMinor break processing - VB code

Dim mintot As Integer, fintot As IntegerDim holddept As String

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.

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.

Page 9: Break Processing Please use speaker notes for additional information!

Minor break processing - VB codeMinor break processing - VB code

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 holddept = deptno End If End If picOutput.Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) fintot = fintot + Val(amt) Else MsgBox "End of File", vbOKOnly, "EOF" picOutput.Print "Dept Total: "; Format(mintot, "Currency") picOutput.Print "Final Total: "; Format(fintot, "Currency") End IfEnd Sub

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.

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.

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.

After checking for breaks, I write the detail line and add to the minor total and final total accumulator.

When EOF has been reached, the minor total line for the last dept must be written. Then the final total line must be written.

Page 10: Break Processing Please use speaker notes for additional information!

Minor.txt"12","500""12","100""12",”050""15",”200""15",”100""15","300""15",”060""17",”020""17","240"

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 holddept = deptno End If End If picOutput.Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) fintot = fintot + Val(amt) Else MsgBox "End of File", vbOKOnly, "EOF" picOutput.Print "Dept Total: "; Format(mintot, "Currency") picOutput.Print "Final Total: "; Format(fintot, "Currency") End IfEnd Sub

holddept

12

holddept is null and deptno is 12 so they are not equal.

holddept is null, else is executed

ProcessingProcessing

It is not EOF

Record is displayed and the amount is added to the accumulators.

mintot

500

fintot

500

Page 11: Break Processing Please use speaker notes for additional information!

Result of first click of Process buttonResult of first click of Process button

picOutput.Print Tab(3); deptno; Tab(7); Format(amt, "Currency")

The tab formatting moves to the designated position. In this case it moves to 3 to display the deptno and then to 7 to display the amt. Note the formatting of the amt to currency.

Minor.txt"12","500""12","100""12",”050""15",”200""15",”100""15","300""15",”060""17",”020""17","240"

Page 12: Break Processing Please use speaker notes for additional information!

Minor.txt"12","500""12","100""12",”050""15",”200""15",”100""15","300""15",”060""17",”020""17","240"

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 holddept = deptno End If End If picOutput.Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) fintot = fintot + Val(amt) Else MsgBox "End of File", vbOKOnly, "EOF" picOutput.Print "Dept Total: "; Format(mintot, "Currency") picOutput.Print "Final Total: "; Format(fintot, "Currency") End IfEnd Sub

holddept

12

holddept and deptno are 12. if ends

ProcessingProcessing

It is not EOF

Record is displayed and the amount is added to the accumulators.

mintot

600

fintot

600

Page 13: Break Processing Please use speaker notes for additional information!

Minor.txt"12","500""12","100""12",”050""15",”200""15",”100""15","300""15",”060""17",”020""17","240"

Processing minor break

Processing minor break

Page 14: Break Processing Please use speaker notes for additional information!

Minor.txt"12","500""12","100""12",”050""15",”200""15",”100""15","300""15",”060""17",”020""17","240"

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 holddept = deptno End If End If picOutput.Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) fintot = fintot + Val(amt) Else MsgBox "End of File", vbOKOnly, "EOF" picOutput.Print "Dept Total: "; Format(mintot, "Currency") picOutput.Print "Final Total: "; Format(fintot, "Currency") End IfEnd Sub

holddept

12

holddept and deptno are 12. if ends

ProcessingProcessing

It is not EOF

Record is displayed and the amount is added to the accumulators.

mintot

650

fintot

650

Page 15: Break Processing Please use speaker notes for additional information!

Minor.txt"12","500""12","100""12",”050""15",”200""15",”100""15","300""15",”060""17",”020""17","240"

Processing minor break

Processing minor break

Page 16: Break Processing Please use speaker notes for additional information!

Minor.txt"12","500""12","100""12",”050""15",”200""15",”100""15","300""15",”060""17",”020""17","240"

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 holddept = deptno End If End If picOutput.Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) fintot = fintot + Val(amt) Else MsgBox "End of File", vbOKOnly, "EOF" picOutput.Print "Dept Total: "; Format(mintot, "Currency") picOutput.Print "Final Total: "; Format(fintot, "Currency") End IfEnd Sub

holddept

12reset to 15

holddept is 12 and deptno is 15 so then is processed.

ProcessingProcessing

It is not EOF

Record is displayed and the amount is added to the accumulators.

mintot

650reset to 0200

fintot

650

850

holddept is not null it is equal to 12

The total is displayed on the screen and then the hold dept is reset to the deptno which is 15 and the minor total is reset to 0.

The total from the accumulator is displayed so you see 650.

Then the mintot is reset to 0.

Then as the record is processed the amount on the record that caused the break is added to mintot and fintot.

Page 17: Break Processing Please use speaker notes for additional information!

Processing minor break

Processing minor break

Minor.txt"12","500""12","100""12",”050""15",”200""15",”100""15","300""15",”060""17",”020""17","240"

Because the record that is being processed has a different department number, a break happened. This caused the department total containing the amount from the accumulator to print. After the total prints, the record that caused the break is processed which results in the display of the record.

Page 18: Break Processing Please use speaker notes for additional information!

Minor.txt"12","500""12","100""12",”050""15",”200""15",”100""15","300""15",”060""17",”020""17","240”EOF

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 holddept = deptno End If End If picOutput.Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) fintot = fintot + Val(amt) Else MsgBox "End of File", vbOKOnly, "EOF" picOutput.Print "Dept Total: "; Format(mintot, "Currency") picOutput.Print "Final Total: "; Format(fintot, "Currency") End IfEnd Sub

holddept

17

ProcessingProcessing

It is EOF

mintot

260

fintot

1570

Page 19: Break Processing Please use speaker notes for additional information!

MsgBox "End of File", vbOKOnly, "EOF"picOutput.Print "Dept Total: "; Format(mintot, "Currency")picOutput.Print "Final Total: "; Format(fintot, "Currency")

EOFEOF

Page 20: Break Processing Please use speaker notes for additional information!

Minor, Intermediate and Major Breaks

Minor, Intermediate and Major Breaks

divno deptno brno amt

"03","24","27","500""03","24","27","600""03","24","27","200""03","24","28","150""03","24","28","275""03","24","28","620""03","25","15","120""03","25","15","175""03","25","15","600""03","25","17","500""03","25","17","100""03","25","20","150""03","25","20","220""04","24","27","125""04","24","27","250""04","24","27","450""04","24","27","600""04","24","28","100""04","24","28","126""04","24","29","600""04","24","29","240""04","25","15","120""04","25","17","600""04","25","17","555"

Page 21: Break Processing Please use speaker notes for additional information!

NOT EOF

INPUT divno, brno, deptno, amt

holddiv = “”

divno, brno and deptno to holddiv, holdbr, holddept

Break check

msgbox

display dept total

display branch total

display division total

display final total

close

Page 22: Break Processing Please use speaker notes for additional information!

holddiv <>divno

display dept total

display branch total

display division total

divno, brno and deptno to holddiv, holdbr, holddept

0 to mintot, intertot, majtot

holdbr <>brno

Break check

display dept total

display branch total

brno and deptno to holdbr, holddept

0 to mintot, intertot

display dept total

deptno to holddept

0 to mintot

display detail line - not done in this program

add to mintot, intertot, majtot

close

Page 23: Break Processing Please use speaker notes for additional information!

Dim mintot As Integer, intertot As Integer Dim majtot As Integer, fintot As Integer Dim holddept As String, holdbr As String Dim holddiv As String

Option Explicit

Private Sub cmdExit_Click() EndEnd Sub

Private Sub Form_Load() Open App.Path & "\MIM.txt" For Input As #1 holddept = "" holdbr = "" holddiv = ""End Sub

Minor, intermediate and major breaksMinor, intermediate and major breaks

These variables are in the general area.

The hold areas are initialized at null.

Using the application path concatenated with a slash and the file name.

Page 24: Break Processing Please use speaker notes for additional information!

Private Sub frmProcess_Click() Dim divno As String, brno As String Dim deptno As String, amt As String If Not EOF(1) Then Input #1, divno, brno, deptno, amt If holddiv = "" Then holddiv = divno holdbr = brno holddept = deptno End If If holddiv <> divno Then picOutput.Print "Dept Total: "; holddept; Tab(20); Format(mintot, "Currency") picOutput.Print "Branch Total: "; holdbr; Tab(20); Format(intertot, "Currency") picOutput.Print "Division Total: "; holddiv; Tab(20); Format(majtot, "Currency") holddiv = divno holdbr = brno holddept = deptno mintot = 0 intertot = 0 majtot = 0 Else

First part of frmProcess_Click()First part of frmProcess_Click()

Page 25: Break Processing Please use speaker notes for additional information!

If holdbr <> brno Then picOutput.Print "Dept Total: "; holddept; Tab(20); Format(mintot, "Currency") picOutput.Print "Branch Total: "; holdbr; Tab(20); Format(intertot, "Currency") holdbr = brno holddept = deptno mintot = 0 intertot = 0 Else If holddept <> deptno Then picOutput.Print "Dept Total: "; holddept; Tab(20); Format(mintot, "Currency") holddept = deptno mintot = 0 End If End If End If Rem picOutput.Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) intertot = intertot + Val(amt) majtot = majtot + Val(amt) fintot = fintot + Val(amt) Else MsgBox "End of File", vbOKOnly, "EOF" picOutput.Print "Dept Total: "; holddept; Tab(20); Format(mintot, "Currency") picOutput.Print "Branch Total: "; holdbr; Tab(20); Format(intertot, "Currency") picOutput.Print "Division Total: "; holddiv; Tab(20); Format(majtot, "Currency") picOutput.Print "Final Total: "; Format(fintot, "Currency") End IfEnd Sub

Second part of frmProcess_Click()Second part of frmProcess_Click()