Visual Basic - Break Processing

Slides:



Advertisements
Similar presentations
Introduction to File I/O How to read & write data to a disk file...
Advertisements

30/04/ Selection Nested If structures & Complex Multiple Conditions.
Programming Logic and Design Fourth Edition, Introductory
VB PROJECT “PROJECT SAMPLES”. For Next Loops Design a VB program that displays in a picture box the first N multiples of an input integer Input 3 exam.
Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
Component 9, Slide 1 CP2030 Copyright © University of Wolverhampton CP2030 Visual Basic for C++ Programmers v Component 9 working with text files and random.
Types of LOOP Structures Do While ……. Loop Do Until …… Loop For …… Next loop.
Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Chapter 6 - Visual Basic Schneider
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
1 Chapter 6 Repetition. 2 Outline & Objectives Loop Structure Loop Structure Elements of a Loop Structure Elements of a Loop Structure Processing Lists.
Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
10- 1 Chapter 10. To familiarize you with  Main types of computer-generated reports  Techniques used for efficient printing of group reports and control.
10-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
InvEasy (Project1) Please use speaker notes for additional information!
Break Processing Please use speaker notes for additional information!
Chapter 7 Code Tables. VB Code Box 7-1 Event Procedure for Compute Button Private Sub hsbExemptions_Change() txtExemptions.Text =Str(hsbExemptions.Value)
Chapter 4: The Selection Process in Visual Basic.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
Array - adding to array at run time Please see speaker notes for additional information!
Data files and databases. Need a control to browse to a file Standard controls for drive folder and list not much use The CommonDialogs control offers.
Edit Programs Please use speaker notes for additional information. Example: payedit.cbl payedit.cbl.
Chapter 6 - Visual Basic Schneider 1 Chapter 6 Repetition.
Chapter 71 Repetition - Do Loops n A Loops, is used to repeat a sequence of statements a number of time n There are two loops commands in Visual Basic.
Random Files Please see speaker notes for additional information!
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Explanation of SAMPLEIF (if88in1.cbl or if88in1.html) Please use speaker notes for additional information!
Delivery and other DO Examples Please use speaker notes for additional information!
Repetition Chapter 6 - Visual Basic Schneider 1  Loop Structure  Elements of a Loop Structure  Processing Lists of Data with Do Loops Chapter 6 -
Two Forms Please use speaker notes for additional information!
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!
Introduction to Files in VB Chapter 9.1, 9.3. Overview u Data Files  random access  sequential u Working with sequential files  open, read, write,
Control Break Processing
COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Maximum Profit Please use speaker notes for additional information!
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Two file sequential file processing (maximum 1 record per id on each file) Please use speaker notes for additional information!
Sequential Processing to Update a File Please use speaker notes for additional information!
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
Chapter 6 - VB 2008 by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study:
Processing multiple files
UNIT 5 Lesson 15 Looping.
Find, filter etc with connection to Access code internally
Data Environment and Grouped Report
Computer Programming I
File Handling Programming Guides.
Department Array in Visual Basic
Programming Logic and Design Fourth Edition, Comprehensive
Structured COBOL Programming
Designing and Writing Control-Break Programs
Minor, Intermediate and Major Breaks
Searching an Array or Table
Python programming exercise
VB Decisions & Conditions
CHAPTER 17 The Report Writer Module
Please use speaker notes for additional information!
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Chapter 8 - Visual Basic Schneider
2 file sequential matching with multiple records allowed on file 2
GCSE Computing:: Selection (IF statements)
More on If statements (Calculate, Calculate1, Calculate2)
Access Click on file and then you want a new database.
Presentation transcript:

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.

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 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 Records from department 12. Dept Amount 12 500 12 100 12 50 15 200 15 100 15 300 15 60 17 20 17 240 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.

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.

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

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.

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.