7 – Arrays Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.

Slides:



Advertisements
Similar presentations
An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
Advertisements

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.
Variables and Constants
 “Regular” variable ◦ Holds a single value ◦ For example Dim Student1 as String Dim Student2 as String Dim Student3 as String … Dim Studentn as String.
Arrays. Arrays  When a value is to be used in a program, a variable is declared to hold that value  What about storing the results of exams for a large.
Arrays-Part 1. Objectives Declare and initialize a one-dimensional array Store data in a one-dimensional array Display the contents of a one-dimensional.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
Chapter 7: Working with Arrays
VB DATATYPES, VARIABLES, CONSTANTS & CALCULATIONS.
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Using Arrays in JavaScript.
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
MAT Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
19/10/20151 Data Structures Arrays. 219/10/2015 Learning Objectives Explain initialising arrays and reading data into arrays. Design and write routine/s.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
1 Mr. Muhammad Hanif Lecturer Information Technology MBBS Campus Dadu University of SIndh.
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.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
9c. Line Charts CSCI N207 Data Analysis Using Spreadsheet Department of Computer and Information Science, IUPUI Lingma Acheson
Arrays. Overview u General Discussion  Uses  Structure  Declaration u Searching u Control Arrays.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Arrays. Lesson Objectives  To understand what an array is and it’s function  To know how code and array in VB.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
Chapter 71 Arrays Creating and Accessing Arrays Using Arrays Some Additional Types of Arrays.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter Arrays, Timers, and More 8.
Other Variable Types Dim lab as String makes a box that can store a label tag Dim ColHead As String ColHead = “function” ColHead function Dim lab as Boolean.
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.
2a – Object Oriented Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
2d – CheckBox Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Arrays Chapter 8. Overview u General discussion u Variable arrays u Control arrays u Multi-dimensional variable arrays  Two-dimensional  Three-dimensional.
2e – RadioButtons Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
6b – Sub Procedure With Parameters Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Chapter 8 P 1 Arrays and Grids Single-dimension arrays Definition An array is a sequence of elements all referred to with a common name. Other terms: table,
CSC Programming for Science Lecture 34: Dynamic Pointers.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Arrays.
2c – Textboxes and Buttons Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Variables in VB. What is a variable? ► A named memory location that stores a value.
5b – For Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
9d. Pie Charts CSCI N207 Data Analysis Using Spreadsheet Department of Computer and Information Science, IUPUI Lingma Acheson
For Friday Read No quiz Program 6 due. Program 6 Any questions?
Arrays [Array, Array, Array, Array] Our Very First Data Structure! Definition - A group of homogeneous elements of a specific data type* Examples: –[a,e,t,w,e,e,y,u,f,v,x,g,h,q,w,r,f,d,a,h,o,a,m,s,z,d]
5a – While Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
FUNCTIONS Introduction to Functions. Do Now Draw each of the following relations as a mapping diagram.
Using Forms and Form Elements In Visual Basic.NET.
6d – Built-in Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Introduction to programming in java Lecture 21 Arrays – Part 1.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
Don’t Leave Home Without them
CSCI N207 Data Analysis Using Spreadsheet
See requirements for practice program on next slide.
Programming Concepts and Database
2g – ComboBox Lingma Acheson CSCI N331 VB .NET Programming
7 – Variables, Input and Output
GCSE Computing:: Selection (IF statements)
2b – Labels and Pictures Lingma Acheson CSCI N331 VB .NET Programming
Programming Concepts and Database
4a- If And Else Lingma Acheson CSCI N331 VB .NET Programming
4d – Program Design Lingma Acheson CSCI N331 VB .NET Programming
Presentation transcript:

7 – Arrays Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming

Represent A List of Values Sometimes we need to represent a list of values that have the similar characteristics. Example 1: Quarterly sales figures of one year. We can use four variables to store them. dblQuarter1 = 12.8 dblQuarter2 = 15.6 dblQuarter3 = 23.2 dblQuarter4 =

Example 2: Names of the products that a vending machine carries. We can use six variables if there are six of them. strName1 = “Pepsi” strName2 = “Sprite” strName3 = “Root Beer” strName4 = “Diet Coke” strName5 = “Mountain Dew” strName6 = “7 up” 3 Represent A List of Values

Example 3: Exam scores of each student in a class. If there are 28 students in the class, do we need 28 variables? Is there a better way? intScore1 = 97 intScore2 = 68 intScore3 = 82 intScore4 = 91 intScore5 = 85 intScore6 = 88 intScore7 = 72 …. 4 Represent A List of Values

What is an array? Yes, use an array! Array - A data structure that holds a list of values of the same type. E.g. –Quarterly sales, an array of 4 values of type Double: –Student scores, an array of 28 values of type Integer: –Name of products in a vending machine, an array of 6 values of type String: …88 CokeSpriteRoot Beer Diet Coke Mountain Dew 7 up

What is an array? Caution – each structure is just one variable! That variable can hold multiple values. E.g. –Quarterly sales: Name of the array: QuarterlySales How many values does the array have: 4 Type of the values: Double –Name of products in a vending machine Name of the array: Products How many values does the array have: 6 Type of the values: String CokeSpriteRoot Beer Diet Coke Mountain Dew 7 up

Values in an Array Now we have a name for the whole structure, how do we refer to each value? E.g. how do I know the sales figure for the third quarter? Answer: Use position to identify a value as array values are stored in order. –E.g. QuarterlySales: 1 st element of QuarterlySales: nd element of QuarterlySales: rd element of QuaterlySales: th element of QuarterlySales:

Values in an Array How do we use VB code to specify a position? Use array indexes that start from 0. E.g. QuarterlySales(0): 12.8 QuarterlySales(1): 15.6 QuarterlySales(2): 23.2 QuarterlySales(3): 18.8 E.g. ‘Initialize all the values to 0 For n = 0 To 3 QuarterlySales(n) = 0 Next

How to create an array? Basic structure: Dim arrayname As datatype() or: Dim arrayname() As datatype E.g. ‘delare an array called dblQuarterlySales that holds Double values Dim dblQuarterlySales As Double() 9

How to create an array? Variations ‘declare an array with 3 as upperbound index. ‘an array of 4 elements. Dim dblQuarterlySales As Double(3) ‘initialize values when declaring the array, no need to specify a size, as four values indicate a size of 4 Dim dblQuarterlySales As Double() = {12.8, 15.6, 23.2, 18.8} 10

Retrieve Values from an Array E.g ‘get the first element from the array and assign it to ‘a variable dblQuarterOne = dblQuarterlySales(0) ‘display result in a textbox txtOutput.Text = “Last quarter sale: “ & _ Cstr(dblQuarterlySales(3)) ‘display all the values in a listbox For n = 0 To 3 lstOutput.Items.Add(Cstr(dblQuarteylySales(n))) Next 11