Break Processing Please use speaker notes for additional

Break Processing Please use speaker notes for additional information!

Minor Break

Minor 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 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" 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.

Minor Break Dim mintot As Integer, fintot As Integer Minor. txt Dim holddept As String "12", "500" Option Explicit "12", "100" Private Sub cmd. Exit_Click() End "12", ” 050" End Sub "15", ” 200" Private Sub Form_Load() "15", ” 100" If Right(App. Path, 1) <> "" Then Open App. Path & "Minor. txt" For Input As #1 "15", "300" Else "15", ” 060" Open App. Path & "Minor. txt" For Input As #1 "17", ” 020" End If holddept = "" "17", "240" End Sub Private Sub frm. Process_Click() Dim deptno As String, amt As String If Not EOF(1) Then Input #1, deptno, amt If holddept <> deptno Then If holddept <> "" Then pic. Output. Print "Dept Total: "; Format(mintot, "Currency") holddept = deptno mintot = 0 Else holddept = deptno End If pic. Output. Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) fintot = fintot + Val(amt) Else Msg. Box "End of File", vb. OKOnly, "EOF" pic. Output. Print "Dept Total: "; Format(mintot, "Currency") pic. Output. Print "Final Total: "; Format(fintot, "Currency") End If End Sub

Input/Output This is the input data each record on the file contains a dept # and an amount. Minor Total Processing Dept 12 12 12 15 15 17 17 Amount 500 100 50 200 100 300 60 20 240 Dept # Amount 12 12 12 500 100 50 Total 12: 15 15 Total 15: Output report that is produced containing the input records and a total each time the department number changed. 17 17 Total 17: Final Total: 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

Minor logic 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 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. When the form is loaded I set the holddept = “”.

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 frm. Process_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 pic. Output. 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 pic. Output. 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. Msg. Box "End of File", vb. OKOnly, "EOF" pic. Output. Print "Dept Total: "; Format(mintot, "Currency") pic. Output. 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 dept # I just read but the hold dept is equal to dept must be written. Then the spaces, then we are dealing with the first record final total line must be written. and we need to move the dept # on the first record to the hold area for department.

Minor. txt "12", "500" It is not EOF "12", "100" "12", ” 050" Private Sub frm. Process_Click() "15", ” 200" Dim deptno As String, amt As String holddept is null and deptno "15", ” 100" If Not EOF(1) Then is 12 so they are not equal. "15", "300" Input #1, deptno, amt "15", ” 060" If holddept <> deptno Then holddept is null, else is executed "17", ” 020" If holddept <> "" Then pic. Output. Print "Dept Total: "; Format(mintot, "Currency") "17", "240" Processing holddept = deptno mintot = 0 Else holddept = deptno holddept End If 12 pic. Output. Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) Record is displayed and the amount is fintot = fintot + Val(amt) added to the accumulators. Else Msg. Box "End of File", vb. OKOnly, "EOF" pic. Output. Print "Dept Total: "; Format(mintot, "Currency") pic. Output. Print "Final Total: "; Format(fintot, "Currency") End If End Sub mintot fintot 500

Result of first click of Process button pic. Output. 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"

Processing It is not EOF Minor. txt "12", "500" "12", "100" "12", ” 050" "15", ” 200" "15", ” 100" holddept and deptno are 12. "15", "300" if ends "15", ” 060" "17", ” 020" "; Format(mintot, "Currency") "17", "240" Private Sub frm. Process_Click() Dim deptno As String, amt As String If Not EOF(1) Then Input #1, deptno, amt If holddept <> deptno Then If holddept <> "" Then pic. Output. Print "Dept Total: holddept = deptno mintot = 0 Else holddept = deptno holddept End If 12 pic. Output. Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) Record is displayed and the amount is fintot = fintot + Val(amt) added to the accumulators. Else Msg. Box "End of File", vb. OKOnly, "EOF" pic. Output. Print "Dept Total: "; Format(mintot, "Currency") pic. Output. Print "Final Total: "; Format(fintot, "Currency") End If End Sub mintot fintot 600

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

Processing It is not EOF Minor. txt "12", "500" "12", "100" "12", ” 050" "15", ” 200" "15", ” 100" "15", "300" holddept and deptno are 12. "15", ” 060" if ends "17", ” 020" "; Format(mintot, "Currency") "17", "240" Private Sub frm. Process_Click() Dim deptno As String, amt As String If Not EOF(1) Then Input #1, deptno, amt If holddept <> deptno Then If holddept <> "" Then pic. Output. Print "Dept Total: holddept = deptno mintot = 0 Else holddept = deptno holddept End If 12 pic. Output. Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) Record is displayed and the amount is fintot = fintot + Val(amt) added to the accumulators. Else Msg. Box "End of File", vb. OKOnly, "EOF" pic. Output. Print "Dept Total: "; Format(mintot, "Currency") pic. Output. Print "Final Total: "; Format(fintot, "Currency") End If End Sub mintot fintot 650

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

Processing It is not EOF Minor. txt "12", "500" holddept is not null it "12", "100" is equal to 12 "12", ” 050" "15", ” 200" "15", ” 100" "15", "300" holddept is 12 and deptno is "15", ” 060" 15 so then is processed. "17", ” 020" "; Format(mintot, "Currency") "17", "240" Private Sub frm. Process_Click() Dim deptno As String, amt As String If Not EOF(1) Then Input #1, deptno, amt If holddept <> deptno Then If holddept <> "" Then pic. Output. Print "Dept Total: holddept = deptno mintot = 0 The total is displayed on the screen and then Else holddept the hold dept is reset to the deptno which is 15 holddept = deptno and the minor total is reset to 0. End If 12 End If reset to 15 pic. Output. Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) Record is displayed and the amount is fintot = fintot + Val(amt) added to the accumulators. Else Msg. Box "End of File", vb. OKOnly, "EOF" pic. Output. Print "Dept Total: "; Format(mintot, "Currency") pic. Output. Print "Final Total: "; Format(fintot, "Currency") End If End Sub The total from the accumulator is displayed so you see 650. mintot Then the mintot is reset to 0. 650 reset to 0 200 Then as the record is processed the amount on the record that caused the break is added to mintot and fintot 650 850

Processing minor break 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. Minor. txt "12", "500" "12", "100" "12", ” 050" "15", ” 200" "15", ” 100" "15", "300" "15", ” 060" "17", ” 020" "17", "240"

Processing It is EOF Minor. txt "12", "500" "12", "100" "12", ” 050" "15", ” 200" "15", ” 100" "15", "300" "15", ” 060" "17", ” 020" "; Format(mintot, "Currency") "17", "240” EOF Private Sub frm. Process_Click() Dim deptno As String, amt As String If Not EOF(1) Then Input #1, deptno, amt If holddept <> deptno Then If holddept <> "" Then pic. Output. Print "Dept Total: holddept = deptno mintot = 0 Else holddept = deptno End If pic. Output. Print Tab(3); deptno; Tab(7); Format(amt, "Currency") mintot = mintot + Val(amt) fintot = fintot + Val(amt) Else Msg. Box "End of File", vb. OKOnly, "EOF" pic. Output. Print "Dept Total: "; Format(mintot, "Currency") pic. Output. Print "Final Total: "; Format(fintot, "Currency") End If End Sub holddept 17 mintot fintot 260 1570

EOF Msg. Box "End of File", vb. OKOnly, "EOF" pic. Output. Print "Dept Total: "; Format(mintot, "Currency") pic. Output. Print "Final Total: "; Format(fintot, "Currency")

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", "175" "03", "25", "15", "600" "03", "25", "17", "500" "03", "25", "17", "100" "03", "25", "20", "150" "03", "25", "20", "220" "04", "27", "125" "04", "27", "250" "04", "27", "450" "04", "27", "600" "04", "24", "28", "126" "04", "29", "600" "04", "29", "240" "04", "25", "120" "04", "25", "17", "600" "04", "25", "17", "555"

NOT EOF INPUT divno, brno, deptno, amt msgbox holddiv = “” divno, brno and deptno to holddiv, holdbr, holddept display dept total display branch total display division total display final total close Break check

close Break check holddiv <> divno display dept total holdbr <> brno display dept total deptno to holddept 0 to mintot display branch total display dept total display branch total brno and deptno to holdbr, holddept 0 to mintot, intertot display division total divno, brno and deptno to holddiv, holdbr, holddept 0 to mintot, intertot, majtot display detail line not done in this program add to mintot, intertot, majtot

Minor, intermediate and major breaks Dim Dim mintot As Integer, intertot As Integer majtot As Integer, fintot As Integer holddept As String, holdbr As String holddiv As String These variables are in the general area. Option Explicit Private Sub cmd. Exit_Click() End Sub Private Sub Form_Load() Open App. Path & "MIM. txt" For Input As #1 holddept = "" holdbr = "" The hold areas are holddiv = "" initialized at null. End Sub Using the application path concatenated with a slash and the file name.

First part of frm. Process_Click() Private Sub frm. Process_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 pic. Output. Print "Dept Total: "; holddept; Tab(20); Format(mintot, "Currency") pic. Output. Print "Branch Total: "; holdbr; Tab(20); Format(intertot, "Currency") pic. Output. Print "Division Total: "; holddiv; Tab(20); Format(majtot, "Currency") holddiv = divno holdbr = brno holddept = deptno mintot = 0 intertot = 0 majtot = 0 Else

Second part of frm. Process_Click() If holdbr <> brno Then pic. Output. Print "Dept Total: "; holddept; Tab(20); Format(mintot, "Currency") pic. Output. Print "Branch Total: "; holdbr; Tab(20); Format(intertot, "Currency") holdbr = brno holddept = deptno mintot = 0 intertot = 0 Else If holddept <> deptno Then pic. Output. Print "Dept Total: "; holddept; Tab(20); Format(mintot, "Currency") holddept = deptno mintot = 0 End If Rem pic. Output. 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 Msg. Box "End of File", vb. OKOnly, "EOF" pic. Output. Print "Dept Total: "; holddept; Tab(20); Format(mintot, "Currency") pic. Output. Print "Branch Total: "; holdbr; Tab(20); Format(intertot, "Currency") pic. Output. Print "Division Total: "; holddiv; Tab(20); Format(majtot, "Currency") pic. Output. Print "Final Total: "; Format(fintot, "Currency") End If End Sub
- Slides: 25