Processing multiple files

Slides:



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

Three file matching Please use speaker notes for additional information!
CS0004: Introduction to Programming Repetition – Do Loops.
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.
Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
Control structures Part 2 iteration control To enable repetition of a statement block.
Program Design and Development
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.
Arrays. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For i = 1 To 4 Input.
Sentinel Logic Assumes while loops and input statements.
5.05 Apply Looping Structures
Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!
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)
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Chapter 4: The Selection Process in Visual Basic.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Logic Structure - focus on looping Please use speaker notes for additional information!
VB Core II Conditional statements Exception handling Loops Arrays Debugging.
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!
Component 4/Unit 5-4. Iteration (Repetition, Looping, Do loops) Loops are used to execute statements repetitively Loops require a conditional test that.
Do Loop with Interest Please see speaker notes for additional information!
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
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.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
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.
Count and add list of numbers From user input and from file.
Delivery and other DO Examples Please use speaker notes for additional information!
22/11/ Selection If selection construct.
Notes on ADO from other projects Please use speaker notes for additional information!
Sequential files School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 12, Monday 4/07/2003)
Two Forms Please use speaker notes for additional information!
6-1 Chapter 6 Working with Arrays in VB.NET. 6-2 Learning Objectives Understand the use of list and table arrays in VB.NET projects and the difference.
VAT Calculator program Controls Properties Code Results.
Pay Example (PFirst98) Please use speaker notes for additional information!
Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!
Maximum Profit Please use speaker notes for additional information!
Using a Database Access97 Please use speaker notes for additional information!
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
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!
Loop Blocks Chapter 6 Part A. Program Blocks 1.Actions- commands, messages, methods 2.Branches- decisions to be made 3.Loops- actions to be repeated.
ADO and DataList, DataCombo and DataGrid Controls Please use speaker notes for additional information!
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
Multiple forms - SDI & MDI Please use speaker notes for additional information!
Visual Basic - Break Processing
UNIT 5 Lesson 15 Looping.
Find, filter etc with connection to Access code internally
Computer Programming I
Please use speaker notes for additional information!
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Please use speaker notes for additional information!
Department Array in Visual Basic
Please use speaker notes for additional information!
Programming Logic and Design Fourth Edition, Comprehensive
Designing and Writing Control-Break Programs
Minor, Intermediate and Major Breaks
Searching an Array or Table
Please use speaker notes for additional information!
Please see speaker notes for additional information!
2 file sequential matching with multiple records allowed on file 2
Introduction to Computer Programming IT-104
Presentation transcript:

Processing multiple files Please use speaker notes for additional information! When you are processing multiple files you can choose to process horizontally which is what I did in the last slide show and in the initial examples. Or you can process vertically which means you can loop through each file until it changes identification number - this means until it no longer matches the identification number in the hold area. This example shows the vertical processing involving three files - the processing for two files is similar and shown in code.

This shows the results of executing the program. File1mul.dat 111011 111001 111010 222002 333003 333033 444004 555055 600006 666600 666060 666006 File2mul.dat 111001 111010 222022 222222 300003 444004 444040 444444 555006 666006 666060 777007 File3mul.dat 111110 111011 112012 222022 333033 333303 444404 666606 666060 This slide shows the three input files and the results. The processing is to combine the three files into one. The logic flowchart is shown on the next slide and the code in VB follows.

START Open files ID1 > ID2 ID2 > ID3 ID1> ID3 ID2 to hold This shows the start which includes establishing the hold area with the lowest id from the three files being processed.

Process with id from hold ID1 = hold Add to accum Read 1 Routine ID2 = hold Add to accum Read 2 Routine ID3 = hold Add to accum Read 3 Routine Process with id from hold and accum - Write The processing is done until there is a 999 in all three files. It could also be set to stop when all 3 files are at end of file. A

A ID1 > ID2 ID2 > ID3 ID1> ID3 ID2 to hold ID3 to hold Establish the smallest id for the hold area. 0 to accum

Option Explicit Dim Data1 As String, Data2 As String, Data3 As String Dim ID1 As String, ID2 As String, ID3 As String Dim AMT1 As Integer, AMT2 As Integer, AMT3 As Integer Dim ID123 As String, AMT123 As Integer Dim wkAccum As Integer Dim wkIdHold As String Private Sub cmdExit_Click() Close #1 Close #2 Close #3 Close #4 End End Sub This starts an example coded in VB. It shows the definition of the work areas/variables and the closing of the files when the program is exited.

Private Sub cmdRun_Click() Do Until (ID1 = "999" And ID2 = "999" And ID3 = "999") Do While ID1 = wkIdHold wkAccum = wkAccum + AMT1 Call ReadFile1 Loop Do While ID2 = wkIdHold wkAccum = wkAccum + AMT2 Call ReadFile2 Do While ID3 = wkIdHold wkAccum = wkAccum + AMT3 Call ReadFile3 ID123 = wkIdHold AMT123 = wkAccum Call Process If ID1 > ID2 Then If ID2 > ID3 Then wkIdHold = ID3 Else wkIdHold = ID2 End If If ID1 > ID3 Then wkIdHold = ID1 wkAccum = 0 End Sub Loop through each file comparing and processing those that match the hold id . Again this is processing each file vertically as opposed to the horizontal processing covered before. This is the code to loop through the records processing each one. Note that if you are doing any kind of special processing and dealing with errors, lots needs to be added to handle those instances.

Private Sub Form_Load() 'This program combines three files into one ’All files can have one or no or many records Dim DBPath As String DBPath = App.Path If Right(DBPath, 1) <> "\" Then DBPath = DBPath & "\" End If Open DBPath & "File1mul.dat" For Input As #1 Open DBPath & "File2mul.dat" For Input As #2 Open DBPath & "File3mul.dat" For Input As #3 Open DBPath & "file123m.dat" For Output As #4 Call ReadFile1 Call ReadFile2 Call ReadFile3 If ID1 > ID2 Then If ID2 > ID3 Then wkIdHold = ID3 Else wkIdHold = ID2 If ID1 > ID3 Then wkIdHold = ID1 End Sub This determines what to initialize wkIdHold at. The lowest id from the three files will be used to initialize.

Private Sub ReadFile1() If Not EOF(1) Then Input #1, Data1 ID1 = Left(Data1, 3) AMT1 = Right(Data1, 3) Else ID1 = "999" End If End Sub Private Sub ReadFile2() If Not EOF(2) Then Input #2, Data2 ID2 = Left(Data2, 3) AMT2 = Right(Data2, 3) ID2 = "999" Private Sub ReadFile3() If Not EOF(3) Then Input #3, Data3 ID3 = Left(Data3, 3) AMT3 = Right(Data3, 3) ID3 = "999" Private Sub Process() picOut123.Print ID123; AMT123 Write #4, ID123 & AMT123 This shows the read and check for EOF and the processing which writes the record containing the id that came from the hold area and the amount that came from the accumulator.