Arrays. Variable Arrays a group of variables that have the same name and data type each element in a variable array is identified by a subscript refer.

Slides:



Advertisements
Similar presentations
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.
Advertisements

 “Regular” variable ◦ Holds a single value ◦ For example Dim Student1 as String Dim Student2 as String Dim Student3 as String … Dim Studentn as String.
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 14, 2005.
Introduction to Computing Dr. Nadeem A Khan. Lecture 27.
Chapter 7 - Visual Basic Schneider1 Chapter 7 Arrays.
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.
Introduction to Computing Dr. Nadeem A Khan. Lecture
1 More on Arrays Passing arrays to or from methods Arrays of objects Command line arguments Variable length parameter lists Two dimensional arrays Reading.
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
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.
Chapter 7 - Visual Basic Schneider1 Chapter 7 Arrays.
Two-Dimensional Arrays School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 11, Friday 4/04/2003)
Chapter seven review. 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.
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.
Chapter 7 - Visual Basic Schneider1 Chapter 7 Arrays.
Chapter 7: Working with 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.
Arrays.
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.
Chapter 7 - Visual Basic Schneider
User-defined Data Types VB provides programmers with the ability to create user-defined types. User-defined Types are collections of related variables.
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.
COMP 14 Introduction to Programming Miguel A. Otaduy June 1, 2004.
IE 212: Computational Methods for Industrial Engineering
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
Array Processing: Exercises School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 10, Friday 3/28/2003)
Chapter 8 Arrays Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
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.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
1 Chapter 7 – Arrays 7.1 Creating and Using Arrays 7.4 Two-Dimensional Arrays.
Variables,Constants and Data types Variables temporarily stores values during the execution of an application Variables have a name and data type Declare.
Lecture Set 12 Sequential Files and Structures Part D - Structures.
8-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Arrays. Overview u General Discussion  Uses  Structure  Declaration u Searching u Control Arrays.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
Pascal Programming Arrays and String Type.
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Chapter 71 Arrays Creating and Accessing Arrays Using Arrays Some Additional Types of Arrays.
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.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
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 More About Array Processing 8.2 There Are Many Uses of Arrays and Many Programming.
Arrays and others. Annoucement Today’s office hour move to Friday 1:00PM to 3:00PM Today’s office hour move to Friday 1:00PM to 3:00PM Today Today  Call.
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.
CHAPTER 9 PART II. MULTIDIMENSIONAL ARRAYS Used to represent tables of values arranged in rows and columns. Table element requires two indexes: row and.
Arrays Chapter 8. Overview u General discussion u Variable arrays u Control arrays u Multi-dimensional variable arrays  Two-dimensional  Three-dimensional.
Chapter 7 - VB.Net by Schneider1 Chapter 7 – Arrays 7.1 Creating and Accessing Arrays 7.2 Using Arrays 7.3 Control Arrays Skip Structures (7.3), 7.4 and.
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.
Chapter81 For....Next Loops n For i = m To n statement (s) Next i n For statement designates a numeric variable, called control variable. n It is initialized.
Arrays An array is an indexed data structure which is used to store data elements of the same data type. An array is an indexed data structure which is.
CiS 260: App Dev I. 2 Introduction to Arrays n An array is an object that contains a collection of components (_________) of the same data type. n For.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
CiS 260: App Dev I. 2 Introduction to Arrays n An array is an object that contains a collection of components (_________) of the same data type. n For.
ILM Proprietary and Confidential -
Two-Dimensional Arrays. Two-dimensional arrays variables store the contents of tables or matrices. Example: Dim arrTable(1 to 5, 1 to 5) As Integer first.
Chapter 9 Arrays. Chapter Objectives Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of “array index.
Visual Basic CDA College Paphos Campus COM123 Visual Programming 1 Lecture: Charalambous Sotiris Week 8: COM123 Visual Programming 1 Lecture: Charalambous.
Lab 5 Arrays ► Lab 4 Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline 1 Introduction 2 Arrays 3Declaring Arrays 4Processing Array Contents 5 Multiple-Subscripted.
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
Chapter 7: Working with Arrays
IS 350 Arrays.
Single Dimensional Arrays
Chapter 7 Arrays.
ARRAYS.
CIS16 Application Development and Programming using Visual Basic.net
Presentation transcript:

Arrays

Variable Arrays a group of variables that have the same name and data type each element in a variable array is identified by a subscript refer to an array element by the name of the array followed by its subscript can have as many as 60 dimensions

Declaring One-dimensional Arrays Syntax: Dim arrayname(lower subscript To upper subscript) As datatype Examples: Dim Friend(1 to 5) As String Dim Sums(20) As Double

Private Sub cmdWhoWon_Click() 'Create array for five strings Dim teamName(1 to 5) As String Dim n As Integer 'Fill array with World Series Winners teamName(1) = "Red Sox" teamName(2) = "Giants" teamName(3) = "White Sox" teamName(4) = "Cubs" teamName(5) = "Cubs" 'Access array of five strings n = Val(txtNumber.Text) picWinner.Cls picWinner.Print "The "; teamName(n); " won World Series number"; n End Sub

Private Sub cmdShow_Click() Dim total As Integer, student As Integer, average As Single Dim nom(1 To 8) As String, score(1 To 8) As Integer Open App.Path & "\SCORES.TXT" For Input As #1 For student = 1 To 8 Input #1, nom(student), score(student) Next student Close #1 total = 0 For student = 1 To 8 total = total + score(student) Next student average = total / 8 picTopStudents.Cls For student = 1 To 8 If score(student) > average Then picTopStudents.Print nom(student) End If Next student End Sub

Static and Dynamic Arrays Static arrays have the dimensions specified in the array declaration. They cannot be redimensioned. A dynamic array can have it's size changed after it has been declared. Dynamic arrays are declared without dimensions specified in the parenthesis. Dim arrayname( ) As datatype

Redimensioning Arrays Use ReDim to change the size of a dynamic array If you use the ReDim command in conjunction with the word Preserve, you can change the size of the array without destroying the data contained inside it.

ReDim Example Dim arrNums( ) As Integer Dim intArraySize As Integer intArraySize = 10 ReDim arrNums(intArraySize) For i = 0 to 9 arrNums(i) = i Next ReDim Preserve arrNums(20) For i = 10 to 19 arrNums(i) = i Next

Private Sub cmdShow_Click() Dim numStudents As Integer, nTemp As String, sTemp As Integer Dim student As Integer, total As Integer, average As Single Dim nom() As String, score() As Integer numStudents = 0 Open App.Path & "\SCORES.TXT" For Input As #1 Do While Not EOF(1) Input #1, nTemp, sTemp numStudents = numStudents + 1 Loop Close #1 ReDim nom(1 To numStudents) As String, score(1 To numStudents) As Integer Open App.Path & "\SCORES.TXT" For Input As #1 For student = 1 To numStudents Input #1, nom(student), score(student) Next student Close #1 total = 0 For student = 1 To numStudents total = total + score(student) Next student average = total / numStudents picTopStudents.Print average End Sub