Lecture Set 12 Sequential Files and Structures Part D - Structures.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Introduction to C Programming
Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
Introduction to the C# Programming Language for the VB Programmer.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
Introduction to Arrays Chapter 7 Why use arrays? To store & represent lists of homogeneous values To simplify program code To eliminate the need to reread.
Loops – While, Do, For Repetition Statements Introduction to Arrays
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
Arrays Array of Controls: several controls, of the same type (Class: a prototype for an object indicating the properties and methods), that have the same.
User-defined Data Types VB provides programmers with the ability to create user-defined types. User-defined Types are collections of related variables.
Control Arrays, Records, and Record Arrays in V.B. Week 10.
Chapter 8 Using Repetition with Loops and Lists. Class 8: Loops and Lists Write Do loops to execute statements repeatedly Write For loops to execute statements.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Java Unit 9: Arrays Declaring and Processing Arrays.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
IE 212: Computational Methods for Industrial Engineering
Visual Basic: An Object Oriented Approach 5: Structured Programming.
Why to Create a Procedure
Lecture Set 5 Control Structures Part D - Repetition with Loops.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Lecture Set 5 Control Structures Part A - Decisions Structures.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
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.
© 2012 EMC Publishing, LLC Slide 1 Chapter 8 Arrays  Can store many of the same type of data together.  Allows a collection of related values to be stored.
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
© 1999, by Que Education and Training, Chapter 8, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Chapter 10 Sequential Files and Structures. Class 10: Sequential Files Work with different types of sequential files Read sequential files based on the.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
I Power Higher Computing Software Development High Level Language Constructs.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
Pascal Programming Arrays and String Type.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
Tutorial 101 Variable Arrays A group of variables that have the same name and data type and are related in some way Can have as many as 60 dimensions.
Chapter 9 Processing Lists with Arrays. Class 9: Arrays Understand the concept of random numbers and how to generate random numbers Describe the similarities.
1 CSC103: Introduction to Computer and Programming Lecture No 24.
Programming with Microsoft Visual Basic th Edition
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 3: Using Variables.
Multiple Items in one Data Object Arrays are a way to store more than one piece of data in a data object, provided that all the data is of the same type.
Arrays. Topics to be Covered... Arrays ◦ Declaration ◦ Assigning values ◦ Array manipulation using loops Multi-dimensional arrays ◦ 2D arrays ◦ Declaration.
Introducing Arrays. Too Many Variables?  Remember, a variable is a data structure that can hold a single value at any given time.  What if I want to.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
More on Variables and Subroutines. Introduction Discussion so far has dealt with self- contained subs. Subs can call other subs or functions. A module.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
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.
Introduction to programming in java Lecture 21 Arrays – Part 1.
© 2004 Pearson Addison-Wesley. All rights reserved October 5, 2007 Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
IS 350 Course Introduction. Slide 2 Objectives Identify the steps performed in the software development life cycle Describe selected tools used to design.
Programming Right from the Start with Visual Basic .NET 1/e
A variable is a name for a value stored in memory.
Object-Oriented Programming: Classes and Objects
IS 350 Arrays.
Object-Oriented Programming: Classes and Objects
Structures Lesson xx In this module, we’ll introduce you to structures.
Chapter 8: More on the Repetition Structure
Chapter 6 Control Statements: Part 2
CIS16 Application Development and Programming using Visual Basic.net
Lecture 9: JavaScript Syntax
Presentation transcript:

Lecture Set 12 Sequential Files and Structures Part D - Structures

Slide 2 Objectives Use structures to store and group data together Structures versus structure variables Structure declarations Accessing structures The with statement More complex data structures

Slide 3 Introduction to Structures A structure is used to store related data items, and groups them together logically A structure can take the place of multiple individual variables The Structure keyword is used to declare a structure Once declared, variables can be declared having the declared data type

Slide 4 Structures (Syntax) [Public | Friend] Structure name variableDeclarations [procedureDeclarations] End Structure

Slide 5 Structures (Syntax, continued) The Structure and End Structure keywords mark the beginning and end of a structure block The Public and Friend keywords mark the accessibility of the structure name defines the structure name Use Pascal case for structure names variableDeclarations contains the structure members procedureDeclarations contains procedures appearing in the structure

Slide 6 Structures (Example 1) Declare a structure named Contact with four members Public Structure Contact Public FirstName As String Public LastName As String Public TelephoneNumber As String Public DateAdded As DateTime End Structure

Slide 7 Structures (Example 2) Declare a structure for cell in a Sudoku Puzzle Grid Public Structure CellType Public Val As Integer Public Potvals As String Public isOriginal as Boolean End Structure

Slide 8 Declaring Structures Structures can be declared in a Class or Module block A Structure block can contain a nested Structure block A Structure block cannot appear inside of a procedure block A structure can have members that are themselves structures

Slide 9 Declaring a Structure Variable Declaring a Structure block does not declare a variable It declares a new data type The syntax to declare a structure variable (of a structured type) is the same as the syntax to declare any other variable Examples: Dim CurrentContact As Contact Dim PreviousContact As Contact Dim SudokuGrid(9,9) As cellType

Slide 10 Declaring a Structure Variable (continued) It's also possible to declare an array of structures Examples: Public ContactList() As Contact ReDim ContactList(9) As Contact

Slide 11 Storing and Retrieving Data From a Structure Assignment statements are used to store and retrieve data from a structure A period (.) separates the structure variable name and the member name Examples: CurrentContact.FirstName = "Joe" CurrentContact.LastName = "Smith" CurrentContact.Telephone = " " CurrentContact.DateAdded = #3/22/2006# SudokuGrid(i,j).Val = newval

Slide 12 Assignment Statements Using Structures 1 Structures can be used on both the left and right side of assignment statements As always, the data types of each side of the expression must match Examples: PreviousContact.FirstName = _ CurrentContact.FirstName PreviousContact.LastName = _ CurrentContact.LastName PreviousContact.Address = _ CurrentContact.Address PreviousContact.DateAdded = _ CurrentContact.DateAdded

Slide 13 Assignment Statements Using Structures 2 Unlike arrays, entire structures may be accessed (all fields accessed together) Example: Dim CurrentContact As Contact Dim PreviousContact As Contact PreviousContact = CurrentContact In the third line, the entire four-component structure CurrentContact is assigned to the PreviousContact Structure The structures of both Structures must be identical

Slide 14 The With Statement (Introduction) The With statement supplies a shorthand way of referencing structure and class members A With block begins with the With statement and ends with the End With statement

Slide 15 The With Statement (Example) With CurrentContact.FirstName = "Joe".LastName = "Smith".Telephone = " ".DateAdded = #3/22/2006# End With

Slide 16 Restrictions on the With Statement Decision-making statements cannot break up a With block Repetition structures cannot break up a With block

Slide 17 Using Arrays of Structures It's possible to declare arrays of structures Following the structure variable name, the array subscript appears Following the array subscript, the structure member appears

Slide 18 Using Arrays of Structures (Example) Store data in the first element of the array named ContactList Private ContactList(99) As Contact ContactList(0).FirstName = "Joe" ContactList(0).LastName = "Smith" ContactList(0).Telephone = " " ContactList(0).DateAdded = #3/22/2006#

Slide 19 Processing Delimited Files Using Arrays of Structures A sequential file can be read into an array of structures Steps: Read the first record performing the priming read In a loop: Parse and process the current record Read the next record until there are no more records

Slide 20 Reading One Record from a File to a Structure