05/02/20161 6 Records. 205/02/2016 Learning Objectives State: The difference between records and arrays. The difference between records and arrays. How.

Slides:



Advertisements
Similar presentations
Accessing Your Data Using Reports, Grids and Queries.
Advertisements

30/04/ Selection Nested If structures & Complex Multiple Conditions.
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.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Mark Dixon, SoCCE SOFT 131Page 1 11 – Arrays of Structures & Modules.
08/09/ Arrays Defining, Declaring & Processing.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
University of Toronto at Scarborough © Andria Hunter, Kersti Wain-Bantin CSCA01 VBA-3 1 Lecture Outline Variable Scope Calling another subprogram Programming.
Visual Basic: An Object Oriented Approach 5: Structured Programming.
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
Chapter 17: Arrays Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Class 3 Programming in Visual Basic. Class Objectives Learn about input/output Learn about strings Learn about subroutines Learn about arrays Learn about.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
07/10/ Strings ASCII& Processing Strings with the Functions - Locate (Instr), Mid, Length (Len), Char (ChrW) & ASCII (Asc)
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.
6.3 List Boxes and Loops Some Properties, Methods, and Events of List Boxes List Boxes Populated with Strings List Boxes Populated with Numbers Searching.
5-1 Chapter 5 The Repetition Process in VB.NET. 5-2 Learning Objectives Understand the importance of the repetition process in programming. Describe the.
1 2.2 Selection Logical Operators. 2 Learning Objectives Explain how the logical operator AND Boolean statements works.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
19/10/20151 Data Structures Arrays. 219/10/2015 Learning Objectives Explain initialising arrays and reading data into arrays. Design and write routine/s.
Databases The Kingsway School. Database Systems Databases are programs which store information in a logical way. Databases have a structure which helps.
# 1# 1 Searching andSorting What is selection sort? What is bubble sort? What is binary search? CS 105 Spring 2010.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
26/10/ Selection Nested If structures & Complex Multiple Conditions.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
30/10/ Iteration Loops Do While (condition is true) … Loop.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
IT Applications Theory Slideshows By Mark Kelly Vceit.com Last modified : 6 Dec 2013 Databases II: Structure, naming, data types, data formats.
04/11/ Arrays 1D Arrays Defining, Declaring & Processing.
22/11/ Selection If selection construct.
Dr. Soha S. Zaghloul2 Let arr be an array of 20 integers. Write a complete program that first fills the array with up to 20 input values. Then, the program.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
IT Applications Theory Slideshows Databases II: Structure, Naming, data types, data formats.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
Two Forms Please use speaker notes for additional information!
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
18/12/ Arrays 2D Arrays Defining, Declaring & Processing.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
31/01/ Selection If selection construct.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
A club in Leicester holds exclusive after party sessions for members only. In order to get into one of the after parties you need to be “on the list”.
1 4.2 Selection Logical Operators. 2 Learning Objectives Explain how the logical operator AND Boolean statements works. Directly testing if text boxes.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Lab 5 Arrays ► Lab 4 Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
26/06/ Iteration Loops For … To … Next. 226/06/2016 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Unit 2 Technology Systems
A variable is a name for a value stored in memory.
Top-down approach / Stepwise Refinement & Sub Procedures
Data Types & File Size Calculations
If selection construct
Do While (condition is true) … Loop
4.1 Strings ASCII & Processing Strings with the Functions
If selection construct
Do … Loop Until (condition is true)
1D Arrays Defining, Declaring & Processing
Text / Serial / Sequential Files
3.1 Iteration Loops For … To … Next 18/01/2019.
Random Access Files / Direct Access Files
To understand what arrays are and how to use them
VB.Net Programming Console Application
Text / Serial / Sequential Files
8 Records 25/07/2019.
Presentation transcript:

05/02/ Records

205/02/2016 Learning Objectives State: The difference between records and arrays. The difference between records and arrays. How to set up a record structure and declare an array of records. How to set up a record structure and declare an array of records. How to store and retrieve the contents of an array of records. How to store and retrieve the contents of an array of records. How to declare a variable that is available on other forms. How to declare a variable that is available on other forms. How to refer to a variable declared as above another form. How to refer to a variable declared as above another form.

305/02/2016 A Record Can store many items of data regardless of data type. An array: Can only store data of one type. Can only store data of one type.

405/02/2016 An array of Records Each column is a field. Each row is a record. Account Number SurnameForenameBalance 45278SmithSally€ JonesJohn€ CainShazad€ WhitePeter €250.00

505/02/2016 Declaring an array of records Declare a single record globally. Structure AccountStructure Structure AccountStructure Dim AccountNumber As Integer Dim Surname As String Dim Forename As String Dim Balance As Decimal End Structure End Structure AccountNumberSurnameForenameBalance

605/02/2016 Declaring an array of records Declare an array of this record. Dim Accounts(4) As AccountStructure Dim Accounts(4) As AccountStructure AccountNumberSurnameForenameBalance

705/02/2016 Declaring an array of records Declare a single record globally. Structure AccountStructure Structure AccountStructure Dim AccountNumber As Integer Dim Surname As String Dim Forename As String Dim Balance As Decimal End Structure End Structure Declare an array of this record. Dim Accounts(4) As AccountStructure Dim Accounts(4) As AccountStructure

805/02/2016 Processing Records Account Number SurnameForenameBalance Sally Accounts(1).Forename = “Sally” Accounts(3).Balance = 100 Console.WriteLine(Accounts(1).AccountNumber)

Declaring an array of records Declare a single record globally. Structure … Structure … Dim … As … End Structure End Structure Declare an array of this record. Dim …(…) As … Dim …(…) As … Record Name Field Names & Data Types Record Array Name Record Name (used above) No. of records req.

1005/02/2016 Declaring an array of records This is like declaring your own data type. The data type is a 1x1 array of field names of various data types. Then you declare a variable which is a 1D array of the 1x1 data type. Which will result in a 2D array of records.

1105/02/2016 Processing records …(Index).FieldName Array of Records Name

6a Student Test Marks Specification: Allow the user to enter up to 10 students and their test marks into an array. Allow the user to enter up to 10 students and their test marks into an array. Allow the user to search for student and see his/her test mark. Allow the user to search for student and see his/her test mark. Allow the user to see all students and their marks. Allow the user to see all students and their marks. Allow the user to reset and enter a new set of students and their marks. Allow the user to reset and enter a new set of students and their marks.

Set up an record structure NameMark Structure StudentStructure Dim Name As String Dim Mark As Integer End Structure

Set up an array of records for 10 students NameMark 'Set up the Students Array with space 10 students. 'It will be used to store each student's name and mark. Dim Students(10) As StudentStructure All code from this point is written (as normal) in the main procedure (i.e. in between Sub Main () & End Sub).

'Will be used to hold the number of students currently in the StudentsArray. Dim NumberOfStudents As Integer 'Will be used to store the required student name. Dim SearchName As String 'Will be used to represent each element of the array. Dim Index As Integer 'Will be used to represent if a name was found. Dim NameFound As Boolean = False 'Will be used to represent if the user wishes to enter another student. Dim EnterAnotherStudent As Boolean = False 'Will be used to represent if the user wishes to search for another student. Dim SearchAgain As Boolean = False 'Will be used to represent if the user wishes to reset. Dim Reset As Boolean = False 'Will be used to represent the user’s request. Dim Request As String = False

Do Console.WriteLine(“Do you wish to ‘Add’, ‘Display’, ‘Search’, ‘Reset’ or ‘Exit’?”) Request = Console.ReadLine If Request = “Add” Then Do 'Increment the Number Of Students to move to next element in the Students Array. NumberOfStudents = NumberOfStudents + 1 'Store the name entered into the Name field of the Students Array. Console.WriteLine(“Enter the student’s name.”) Students(NumberOfStudents).Name = Console.ReadLine 'Store the mark entered into the Mark field of the Students Array. Console.WriteLine(“Enter the student’s mark.”) Students(NumberOfStudents).Mark = Console.ReadLine Console.WriteLine(“Do you want to add another student (True/False)?”) EnterAnotherStudent = Console.ReadLine Loop Until EnterAnotherStudent = False ‘Enter Another student?

ElseIf Request = “Display” Then 'Loop through the Students array and display each student's name and mark (with a space between). For Index = 1 To 10 Console.WriteLine(Students(Index).Name & " " & Students(Index).Mark) Next Index

ElseIf Request = “Search” Then Do 'Store the required student. Console.WriteLine(“Enter a student’s name to search for.”) SearchName = Console.ReadLine 'Loop through each element of the Students array and look for the student name entered. For Index = 1 To 10 'Has the student name been found? If Students(Index).Name = SearchName Then 'If so, show the student's mark. Console.WriteLine(SearchName & “’s mark is: ” & Students( Index ).Mark) NameFound = True Exit For End If Next Index ‘Inform the user if the name was not found. If NameFound = False Then Console.WriteLine("The name was not found!") End if Console.WriteLine(“Do you want to search for another student (True/False)?”) SearchAgain = Console.ReadLine Loop Until SearchAgain = False ‘Search for another student?

ElseIf Request = “Reset” Then 'Set the number of students back to 0. NumberOfStudents = 0 End If Loop Until Request = “Exit” ‘Exit?

Now: 1.Enter 5 student names and marks. 2.Search for a student you have entered and check the correct mark is returned. 3.Search for a student you have not entered and check you get a “Not found” message. 4.Check all students and their marks are as you entered them. 5.Reset. 6.Enter 2 new student names and marks. 7.Search for a student you entered previously but not this time. 8.Check all students and their marks. What happens? What should happen? Why does this happen? 20 Reset Working?

Reset the array of records Add the following code in the black rectangle: Add the following code in the black rectangle: ElseIf Request = “Reset” Then 'Set the number of students back to 0. NumberOfStudents = 0 ‘Arrays may contain values from previous ‘Arrays may contain values from previous ‘processing. If they do then programs will use this ‘processing. If they do then programs will use this ‘data and give incorrect results. ‘data and give incorrect results. 'Loop through the array and clear each name and mark. 'Loop through the array and clear each name and mark. For Index = 1 To 10 For Index = 1 To 10 Students(Index).Name = "" Students(Index).Mark = 0 Next Index Next Index End If Loop Until Request = “Exit” ‘Exit?

6a Student Test Marks Run the program and test it.

Commenting on Records For the presentation 6 I will only ask for comments to Records. Your comments MUST explain: What is the record for? And if it is important: How many elements and why this number? And when it is being used: What are you storing or retrieving? When (after and before what) are you doing this and why does it have to be done there? When in the procedure code or, if it is on its own, in which procedure (button, checkbox, textbox, etc…)?

2405/02/2016 Extension “Estate Agency Records” Program 6b An Estate Agency has a program which stores details of the last 10 queries made. These are held in an array which contains, for each query made, the following: The name of the customer The name of the customer The number of bedrooms requested The number of bedrooms requested The date on which the query was made The date on which the query was made Whether the customer asked for details of a property or not (As Boolean – Yes/No). Whether the customer asked for details of a property or not (As Boolean – Yes/No). Write a program which allows: 10 queries to be stored. 10 queries to be stored. When a name is entered it displays all their query’s details. When a name is entered it displays all their query’s details. Displays all queries stored. Displays all queries stored. A reset option. A reset option.

2505/02/2016 Extension “Health Club” Program 6c Store the following details of members of a health club in an array of records: Name Name Date of Birth (DOB) Date of Birth (DOB) Weight (kg) Weight (kg) Height (m) Height (m) Write a program which allows: Member details (as above) to be stored. Member details (as above) to be stored. When a name is entered it displays all their query’s details. When a name is entered it displays all their query’s details. Displays all member details stored. Displays all member details stored. A reset option. A reset option.

2605/02/2016 Plenary What is the difference between records and arrays?

2705/02/2016 A Record Can store many items of data regardless of data type. An array: Can only store data of one type. Can only store data of one type.

2805/02/2016 Plenary How can we set up a record structure and declare an array of records?

2905/02/2016 Declaring an array of records Declare a single record globally. Structure AccountStructure Structure AccountStructure Dim AccountNumber As Integer Dim Surname As String Dim Forename As String Dim Balance As Decimal End Structure End Structure Declare an array of this record. Dim Accounts(4) As AccountStructure Dim Accounts(4) As AccountStructure

3005/02/2016 Plenary How do we store and retrieve the contents of an array of records?

3105/02/2016 Processing records …(Index).FieldName Array of Records Name