Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter Arrays, Timers, and More 8.

Slides:



Advertisements
Similar presentations
Chapter 8 Arrays, Timers, and More.
Advertisements

Tony Gaddis Kip Irvine STARTING OUT WITH Visual Basic 2008
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Introduction to arrays
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 9- 1.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18 Indexing Structures for Files.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Chapter 9 Introduction to Arrays
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Part 1 Conditionals and Loops.
© 2011 Pearson Education, publishing as Addison-Wesley 1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 6 focuses.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Chapter 8 Arrays and More.
1 Introduction to Arrays Problem: –Input 5 scores, compute total, average –Input Example –test scores,employees,temperatures.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
 2006 Pearson Education, Inc. All rights reserved Arrays.
Chapter 8 Arrays Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
CSCI Chapter 8 Arrays Instructor: Bindra Shrestha University of Houston – Clear Lake.
Week Arrays, Timers, and More 9. 2 Introduction Arrays are like groups of variables that allow you to store sets of similar data A single dimension array.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
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.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1 Functions.
Arrays Chapter 8. Chapter 8 - Part 12 Variable and Variable Array Variable Stores only one value Variable Array Variable that has 1 symbolic name but.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 1.
8-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 8 Arrays and More.
Arrays. Overview u General Discussion  Uses  Structure  Declaration u Searching u Control Arrays.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
1 Chapter 7 Arrays. 2 Topics 7.1 Arrays Hold Multiple Values 7.2 Accessing Array Elements 7.3 No Bounds Checking in C Array Initialization 7.5 Processing.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley More About Array Processing 8.2 There Are Many Uses of Arrays and Many Programming.
Arrays Chapter 8. Overview u General discussion u Variable arrays u Control arrays u Multi-dimensional variable arrays  Two-dimensional  Three-dimensional.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved. - Edited By: Maysoon Al-Duwais 1.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
Arrays An array is a list or series of values all referenced by the same name Also referred to as a table An element is an individual item in the array.
Arrays and More CHAPTER 8. INTRODUCTION Arrays are like groups of variables that allow you to store sets of similar data A single dimension array is useful.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 7: Arrays.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Arrays Hold Multiple Values 7.1.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
Data Storage So far variables have been able to store only one value at a time. What do you do if you have many similar values that all need to be stored?
Chapter 8 Arrays and More. Chapter 8 Arrays and More.
2. Understanding VB Variables
Chapter 8 Arrays, Timers, and More.
Visual Basic .NET BASICS
EKT150 : Computer Programming
Starting Out with Programming Logic & Design
Programming In Visual Basic .NET
Presentation transcript:

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter Arrays, Timers, and More 8

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 2 Introduction Arrays are like groups of variables that allow you to store sets of similar data A single dimension array is useful for storing and working with a single set of data A multidimensional array can be used to store and work with multiple sets of data Array programming techniques covered Summing and averaging all the elements in an array Summing all the columns in a two-dimensional array Searching an array for a specific value Using parallel arrays

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Arrays 8.1 An Array Is Like a Group of Variables With One Name You Store and Work With Values in an Array by Using a Subscript

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 4 Array Characteristics An array stores multiple values of same type Like a group of variables with a single name For example, the days of the week would be: a set of 7 string variables maximum length of 9 characters All variables within an array are called elements and must be of the same data type You access the elements in an array through a subscript

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 5 Subscript Characteristics A subscript, also known as an index, is a number that identifies a specific element within an array Subscript numbering works like the index for a list box: Subscript numbering begins at 0 1st element in an array is always subscript 0 Last element is total number of elements - 1

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 6 Declaring an Array ArrayName is the variable name of the array UpperSubscript is the value of the array's highest subscript Must be a positive whole number DataType may be any valid Visual Basic data type VB knows an array is declared when name is followed by number of elements in parens Dim ArrayName(UpperSubscript) As DataType

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 7 Array Declaration Example hours(0) hours(1) hours(2) hours(3) hours(4) hours(5) Dim hours(5) As Integer Note that 6 elements are available when an array with an uppersubscript of 5 is declared Each element is an integer type

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 8 Default Initialization All elements of an Integer array are initialized to zero Same initialization as an integer variable Each array element is initialized exactly the same as a simple variable of that data type A Single is initializled to zero (0.0) A String is initialized to nothing (empty string)

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 9 Implicit Array Sizing & Initialization An array can be initialized when declared Example: This array is implicitly sized Upper subscript value is left blank Number of elements implied from initialization Upper subscript of 5 implied by this example A 6 element array is declared Elements are assigned the values shown Dim numbers() As Integer = {2, 4, 5, 7, 9, 12}

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Named Constant as Upper Subscript A named constant may be used as an array's highest subscript instead of a number A common use for named constants Highest subscript is often used multiple times If highest subscript changes, use of a named constant allows it to be changed in one place Const UPPER_SUB As Integer = 100 Dim array(UPPER_SUB) As Integer

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Arrays and Loops Loops are frequently used to process arrays Use a loop to prompt for 10 values Use a loop to reset values in the names array to an empty string Dim count As Integer For count = 0 To 9 series(count) = CInt(InputBox("Enter a number")) Next count Dim count As Integer For count = 0 To 999 names(count) = "" Next count

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Array Bounds Checking Visual Basic checks each subscript value of each array reference used at run time A subscript is invalid if it is Negative Greater than the UpperSubscript declared An invalid subscript causes VB to throw an exception Bounds checking is not done at design time

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide For Each … Next Statement This statement is similar to a For…Next Iterates for each element in the array strName assigned value of next array element at each iteration Tutorial 8-1 demonstrates array processing Dim employees As String() = {"Jim", "Sally", _ "Henry", "Jean", "Renee"} Dim strName As String For Each strName In employees MessageBox.Show(strName) Next name